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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not able to run a AWK script in korn Shell

Status
Not open for further replies.

udaybo

Programmer
Jun 2, 2008
23
US
Hello,

The below AWK script runs fine in unix , but when I try to run the same in korn shell it gives me an error

awk 'BEGIN {FS="~"};{printf "%010d%-8s%09s\n",$1,$2,$3}' $DC_FIL/red2.txt > $DC_FIL/red3.txt

errors:
Syntax error near line 1
Bailing out near line 1

Can anybody please help me on this.

Thank you
 

Try without the embeded ';':
Code:
awk -F'~' '{printf "%010d%-8s%09s\n",$1,$2,$3}' $DC_FIL/red2.txt > $DC_FIL/red3.txt
[3eyes]




----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thank you, it works but when I use the same logic on a larger script it does not.

Don't know why

awk -F'~' '{printf "%010d%-8s%09s%32s%-32s%-65s%-10s%-2s%-28s%-4s%-2s%-8s%-2s%-20s%-3s%-6s%-4s%10s%-50s%16s16s%4s%4s%20s%20s%4s%4s%4s%4s%4s%4s%4s%4s%4s%1s%-8s%4s%4s%8s%1s%1s%8s%1s%1s%1s%4s%4s%4s\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48}' $DC_FIL/red2.txt > $DC_FIL/red3.txt
 

What is the error?

Also I remember having an issue when the field number was greater than some two digit number, try using squirly brackets for field numbers larger than maybe 9 "${10}, ${11},..."


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thank you LKBrwn, I ran the below script and it ran fine.

/usr/bin/nawk -F'~' '{printf "%010d%-8s%--------------

Thanks Again for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top