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!

awk in sh and bash works differently???

Status
Not open for further replies.

rnbwkat

Programmer
Dec 9, 2009
2
US
Have a problem with a simple awk script that continues to give me the classic "field $() is not correct" and the kicker is that this worked fine under ksh on HP, but under bash and AIX it fails - help??

script:

VARLVL_ID="^M^L"
VLENGTH=0
FTP_AWK='
BEGIN{
VARLVL_ID=v;
VLENGTH=l;
VLIFOUND=0;
}{
if ( substr($0,1,VLENGTH) == VARLVL_ID && VLIFOUND == 0 ) {
$PRINT "";
VLIFOUND=1;
}
else if ( substr($0,1,VLENGTH) == VARLVL_ID && VLIFOUND == 1 )
$PRINT "^L";
else if ( substr($0,1,2) == "^M^M" )
$PRINT "";
else
$PRINT $0;
}'


inside of bash script:

cat ${FILENAME} | awk -v v="$VARLVL_ID" -v l="$VLENGTH" "${FTP_AWK}" > ${NEWFILENAME}.ftp
 
I don't understand how it worked anywhere... are you certain it wasn't modified? All occurrences of $PRINT should just be print.

Annihilannic.
 
so sorry all - I am an idiot. Sometimes you stare at things much too long. In my haste to fix things - well, the print statements in the ksh script were replaced with $PRINT and then an assignment of echo/printf in various places to fix things. Somehow the awk print got replaced as well and just got overlooked. Yes, when the $PRINT was put back to print in the awk script it worked. I found it about 5 minutes after posting this and don't see a way to delete a post, only yo reply to it..
 
We learn more from our moments of idiocy than our moments of brilliance... :)

Annihilannic.
 
rnbwkat, only way to delete a post/entire thread is to use the link:

Inappropriate post?
If so, Red Flag it!


found at the bottom of any post, That way you can send a message to the webmaster explaining that you want the post or the entire thread removed and why...

But good for you you found the solution yourself.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top