jewbolt
asked on
Simple awk just not working - please help
I'm trying to get an awk to work that will look at a file that is | delimitered and print out a field value.
For some reason I can't get it to work and it keeps complaining about a missing } character.
As a test I tried some basic web samples, and they fail in a similar way.
eg.
root> sed 1q /etc/passwd | awk '{ FS = ":" ; print $1 }'
syntax error The source line is 1.
The error context is
{ FS = ":" >>> <<<
awk: The statement cannot be correctly parsed.
The source line is 1.
awk: There is a missing } character.
I'm running this on HP-UX B.11.31 U ia64, but I got the same error on a old SCO server too.
Can someone please put me out of my misery. I must be missing something very simple.
Thanks
For some reason I can't get it to work and it keeps complaining about a missing } character.
As a test I tried some basic web samples, and they fail in a similar way.
eg.
root> sed 1q /etc/passwd | awk '{ FS = ":" ; print $1 }'
syntax error The source line is 1.
The error context is
{ FS = ":" >>> <<<
awk: The statement cannot be correctly parsed.
The source line is 1.
awk: There is a missing } character.
I'm running this on HP-UX B.11.31 U ia64, but I got the same error on a old SCO server too.
Can someone please put me out of my misery. I must be missing something very simple.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hmm,
I found that the following worked!
cat file.090101 | awk -F'|' '{ print $2 $11 $18 }'
Can you not have a -f <filename> mixed with a -F<FS>?
I found that the following worked!
cat file.090101 | awk -F'|' '{ print $2 $11 $18 }'
Can you not have a -f <filename> mixed with a -F<FS>?
the -f with awk is to instruct awk to take script (awk script) from the file and not command line.
ASKER
Oh, how embarrassing!
I thought it was specifying the data input file.
Thank you for your patience.
I thought it was specifying the data input file.
Thank you for your patience.
Welcome :)
No need for sed
awk -F: 'NR==1 {print $1}' /etc/passwd
awk -F: 'NR==1 {print $1}' /etc/passwd
ASKER
Incorporating that format into my solution, I tried the following, where I wanted to specify a pipe char '|' as the delimiter and print out specific columns of a | delimitered .csv file.
root> awk -F'|' -f file.090101.csv '{ print $2 $11 $18 }'
syntax error The source line is 1.
The error context is
>>> Entered|PagerId <<< |Centre|Tran|Operator|Mach
awk: There are 3 extra ) characters.
awk: Quitting
The source line is 1.
Can you see something that stands out as being wrong?