Article 4STC6 Search a variable and a string in a file using AWK

Search a variable and a string in a file using AWK

by
socalheel
from LinuxQuestions.org on (#4STC6)
I am trying to find two strings in a file, the first string will be a timestamp using a variable and the second string will always be POST

i'd like to get this accomplished with one awk command and i cannot figure it out.

I am starting out with this: Code:awk '/POST/ && -v timestamp=`date -d '1 hour ago' '+%d/%b/%Y:%H:'` '{ print $1 } filename.txt''I know the variable portion of this works, but I don't know how to combine it to also search for POST.
can someone point me in the right direction?

example.
here is my file i am searching in:
Code:4.4.4.4 (10.0.2.60) - - [18/Oct/2019:15:38:08 +0000] "GET /customer/ HTTP/1.1" 200 229 "https://www.site.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299" **0/152411**
- (10.0.2.60) - - [18/Oct/2019:15:38:09 +0000] "GET /heartbeat.txt HTTP/1.1" 200 6 "-" "ELB-HealthChecker/2.0" **0/8734**
4.4.4.4 (10.0.1.183) - - [18/Oct/2019:15:38:08 +0000] "GET /customer/ HTTP/1.1" 200 10136 "https://site.com/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36" **0/438338**
5.5.5.5 (10.0.1.183) - - [18/Oct/2019:15:38:08 +0000] "POST /rest/ HTTP/1.1" 400 53 "-" "Throwback/200.0.4 ( 89 )" **0/376289**
5.5.5.5 (10.0.1.183) - - [18/Oct/2019:15:38:10 +0000] "POST /rest/ HTTP/1.1" 400 53 "-" "Throwback/200.0.4 ( 89 )" **0/367578**
5.5.5.5 (10.0.1.183) - - [18/Oct/2019:15:38:11 +0000] "POST /sale.html HTTP/1.1" 200 9256 "https://www.site.com/sale.html?p=5" "Mozilla/5.0 (Linux; Android 7.0; SM-T813) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.116 Safari/537.36" **0/689643**
I need to find every line that has the previous hour and the word POST and print out the first column. In this example, I would need 5.5.5.5 printed out 3 timeslatest?d=yIl2AUoC8zA latest?i=dog3zrJ6iAs:v32qAXWabVc:F7zBnMy latest?i=dog3zrJ6iAs:v32qAXWabVc:V_sGLiP latest?d=qj6IDK7rITs latest?i=dog3zrJ6iAs:v32qAXWabVc:gIN9vFwdog3zrJ6iAs
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments