awk to print all lines after a pattern is found

Is there a way with aw to print all lines after a string is found

There is a file like this

.......
........
2012/19/11 :11.58 PM some data
lne no date
2012/19/11 :11.59 PM some other data
2012/20/11 :12.00 AM some other data
some line without dates
some more lines without dates
2012/20/11 :12.01 AM some more data
....
.......

I need a way to display all lines after the first occurrence of the string 2012/20/11

That is


2012/20/11 :12.00 AM some other data
some line without dates
some more lines without dates
2012/20/11 :12.01 AM some more data
....
.......

print section of file from regular expression to end of file

awk '/2012\/20\/11/,EOF { print $0 }' filename
1 Like

Hi

awk '/2012\/20\/11/{f=1;}f' file

Guru.

sed -n '\|2012/20/11|,$p' infile

Substitute your pattern for PAT :

awk '/PAT/,0' file

Regards,
Alister

How can I pass the date string pattern as variable
I am trying to run this in a shell script.
In the following way

awk -v x="11\/20\/12" '/x/,EOF{print $0}' datefiltertestfile.txt

This is not working

awk -v x='11/20/12' '$0~x,EOF' datefiltertestfile.txt
1 Like
dt="11/20/12"
echo $dt
11/20/12
new_dt=`echo $dt | awk -F'/' '{ print "20"$3"/"$2"/"$1 }' | sed 's#\/#\\\/#g'`
echo $new_dt
2012\/20\/11
nawk '/'"$new_dt"'/,EOF { print $0 }' datefiltertestfile.txt

2012/20/11 :12.00 AM some other data
some line without dates
some more lines without dates
2012/20/11 :12.01 AM some more data
....
.......

Not a single match attempt in an OP post has actually used or required a pattern. They've all been literal matches. If that's always going to be the case, I would recommend using a simpler, less error-prone literal match in favor of regular expression pattern matching.

If the date is the first text on a line and is followed by whitespace, as is the case in the samples:

awk '$1==x,0' x=11/20/12

For a more general solution which matches the string at any location in a line:

awk 'index($0,x),0' x=11/20/12

Regards,
Alister