awk command not working

Hi all,

Trying to write a script that reads a file and prints everything after a certain string is found to the end of the file. Awk is giving me an error and not sure why it doesn't work:

 
# cat test_file
Mon Nov 16 2009 16:11:08
abc
def
Tue Nov 17 2009 16:08:06
ghi
jkl
Wed Nov 18 2009 08:11:06
mno
pqr
Thu Nov 19 2009 13:21:56
stu
vwx

I want everything after Tue Nov 17 2009 16:08:06 but get a syntax error. Can someone show me what I am doing wrong?

 
# awk '/Tue Nov 17 2009 16:08:06/,0' test_file
awk: syntax error near line 1
awk: bailing out near line 1
 

Figured it might be the : but I also try

 
# awk '/Tue/,0' test_file
awk: syntax error near line 1
awk: bailing out near line 1
 

And end up with the same error...

Try

awk '/Tue Nov 17 2009 16:08:06/ {P = 1} P' test_file

If it's Solaris use nawk or /usr/xpg4/bin/awk
(as we always like to say!)

 awk '/Tue Nov 17 2009 16:08:06/{p++}(p)' infile
Tue Nov 17 2009 16:08:06
ghi
jkl
Wed Nov 18 2009 08:11:06
mno
pqr
Thu Nov 19 2009 13:21:56
stu
vwx

LOL :slight_smile:

Thanks.
Using nawk fixed it.

sed '/Tue Nov 17 2009/,$ !d' infile
sed -n '/Tue Nov 17 2009/,$p' urfile

New question...
How do I print every line after the last occurrence of the pattern?

tac infile|sed '1,/Tue Nov 17 2009/ !d'|tac

:wink:

---------- Post updated at 19:58 ---------- Previous update was at 19:49 ----------

 awk 'p{s=s"\n"$0}END{print s}/Tue Nov 17 2009/{s=$0;p=1}' infile

Another approach:

awk 'NR==FNR{if($0 ~ "Tue Nov 17 2009"){n=NR}next}FNR>=n' file file