Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk syntax question

Status
Not open for further replies.

hcclnoodles

IS-IT--Management
Jun 3, 2004
123
GB
Hi there could someone explain what is happening in the following function/statement for me, im just a little confused

'BEGIN{FS=","}
{
printf ("%-11s,%s%s%s,%07.2f,%14s,%-3s\n",$1,substr($2,9,2),substr($2,6,2),substr($
2,3,2),$9,$10,$12)
}

this function is called later in the script by using

awk "$code"


any guidance would be greatly appreciated

cheers
 
sorry it should read

code = 'BEGIN{FS=","}
{
blah blah ....
 
'BEGIN{FS=","}
{
printf ("%-11s,%s%s%s,%07.2f,%14s,%-3s\n",$1,substr($2,9,2),substr($2,6,2),substr($
2,3,2),$9,$10,$12)
}

cat file | awk "$code"

Essentially is processing a comma delimited file.
and printing to stdout.

prints 1st element -11 bytes left justified.
2nd pos 9 for 2 bytes
2nd pos 6 for 2 bytes
2nd pos 3 for 2 bytes
9th floating #
10th 14 bytes
12th 3 bytes left justified

of each line in file
awk has to have something piped or just will wait for input on stdin.
 
And, as usual: man awk

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top