awk command not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command not working
# 1  
Old 11-17-2009
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:

Code:
 
# 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?

Code:
 
# 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

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

And end up with the same error...
# 2  
Old 11-17-2009
Try

Code:

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!)
# 3  
Old 11-17-2009
Code:
 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 Smilie
# 4  
Old 11-17-2009
Thanks.
Using nawk fixed it.
# 5  
Old 11-17-2009
Code:
sed '/Tue Nov 17 2009/,$ !d' infile

# 6  
Old 11-17-2009
Code:
sed -n '/Tue Nov 17 2009/,$p' urfile

# 7  
Old 11-18-2009
New question...
How do I print every line after the last occurrence of the pattern?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command not working as expected

Following one line of awk code removes first 3 characters from each line but when I run the same code on another linux platform it doesn't work and only prints blank lines for each record. Can anyone please explain why this doesn't work? (31 Replies)
Discussion started by: later_troy
31 Replies

2. Shell Programming and Scripting

Awk: System command not working in awk

Hi, I have around 10 files in a folder in which I want to change the file format from tab(\t) to pipe(|) with some changes in the fields as well. Below is the code, while tmp file is getting generated but move command is not working, please help Following is the code awk -F"\t" '{print... (2 Replies)
Discussion started by: siramitsharma
2 Replies

3. Shell Programming and Scripting

awk command on .DAT file not working?

Hi All, I am trying to run awk command on .DAT file and it is not working. The same command is working on .txt file: Contents of the file ZZ_55555555_444444_ZZZZZZ_7777777_888_99.DAT: HEADER|ZZ_55555555_444444_ZZZZZZ_7777777_888_99.DAT... (10 Replies)
Discussion started by: sagar.cumar
10 Replies

4. Shell Programming and Scripting

awk - System command not working

dear All, my awk system command isn't working or rather I'm missing something in my command. Appreciated , if anyone can assist me what exactly I'm missing ?? awk ' /^/ { > c=split($3,a,"/") ;for(n=1; n<=c; ++n) > { > if (system("test -d" /home/cubedata/20120104/"$1"/"a")) { > print... (5 Replies)
Discussion started by: manas_ranjan
5 Replies

5. Shell Programming and Scripting

AWK command working different in Linux

Hi All I have fired a command in linux table=`echo ${file_name} | awk '{FS="/"; print $NF}' | awk '{FS="."; print $1}'` where file_name has /data/ds/dpr_ebicm_uat/backfill/temp/etl_app_info.csv /data/ds/dpr_ebicm_uat/backfill/temp/etl_app_jobs.csv ... (10 Replies)
Discussion started by: vee_789
10 Replies

6. UNIX for Advanced & Expert Users

Awk expressions working & not working

Hi, Putting across a few awk expressions. Apart from the last, all of them are working. echo a/b/c | awk -F'/b/c$' '{print $1}' a echo a/b/c++ | awk -F'/b/c++' '{print $1}' a echo a/b/c++ | awk -F'/b/c++$' '{print $1}' a/b/c++ Request thoughts on why putting a '$' post double ++... (12 Replies)
Discussion started by: vibhor_agarwali
12 Replies

7. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

8. Shell Programming and Scripting

awk command not working from the shell script

Hi, When i run the below command i am able to get the output. awk '/BEGIN DSSUBRECORD/{c=3;next}c-->0' abc.txt | awk '/END DSSUBRECORD/{exit}{print}' | awk '/Owner/{exit}{print}' | awk '{n2=n1;n1=n;n=$0;if(NR%3==0){printf"%s,%s,%s\n",n2,n1,n}}' Output: Name "file_name", ... (5 Replies)
Discussion started by: onesuri
5 Replies

9. Shell Programming and Scripting

sub option of awk command not working with "\" character.

Hi all, I would like to replace some string in a text file by some string which would contains special characters like "/","\". I.e. I have a text file with the statement contactperson somewhere in it. Now I want to replace it by something else which includes special characters like "/","\" ... (1 Reply)
Discussion started by: shareef
1 Replies

10. Shell Programming and Scripting

awk system() command not working

I am using Sun Solaris 5.8 I am trying to run a system command such as ls and echo inside awk, but when I run the following code system echo is not displayed. bash-2.03$ ls | awk 'BEGIN { print "first print" system("echo system echo") print "second print" ... (1 Reply)
Discussion started by: rakeshou
1 Replies
Login or Register to Ask a Question