Strange problems with awk

Joined
Aug 22, 2011
Messages
3
Reaction score
0
Points
1
Hello all,

I am a developer, and have just got my brand new iMac. I've always used Linux, and the switch has not been particularly hard so far..

However, I have a very simple awk script which I am using as part of an installation procedure, which refuses to work properly. All it does is replace all occurences of a specific string in a text file. The command is:

awk '{ gsub("<OPSPWD>", OPSPATH, $0); print > FILENAME}' OPSPATH=$OPS_PATH $OPS_PATH/somefile.txt

When I run the command, the subtitutions happen correctly but awk places itself in an infinite loop repeating the last 2 lines of the text file. If I use a different output file however (i.e. replace FILENAME with "anotherfile.txt") the commands runs without problems. What is even more strange is that on a couple of other Macs I've had the chance to try this out on the command runs fine.

Has anyone else run into this type of problem before? Does the awk implementation for Mac have any problems in reading and writing back to the same file? Is there a fix? I can't seem to find any info using google on this issue so I decided to register and post here.

I'm using a brand new Intel i5 iMac, OSX v.10.6.8

Thanks very much for any replies,
Antonis
 

chscag

Well-known member
Staff member
Admin
Joined
Jan 23, 2008
Messages
65,248
Reaction score
1,833
Points
113
Location
Keller, Texas
Your Mac's Specs
2017 27" iMac, 10.5" iPad Pro, iPhone 8, iPhone 11, iPhone 12 Mini, Numerous iPods, Monterey
I moved your post to this forum where you may have better luck getting answers to your question. This is where it should have been posted rather than the "Switcher" forum.
 
Joined
Sep 8, 2011
Messages
1
Reaction score
0
Points
1
This MIGHT be a similar problem (I'm a newbie) - same machine: -version 10.6.8

awk <plink.356.assoc '{s += $9} END {print FILENAME,",", s/NR}'

It never prints the filename, but only:
, 0.510662

However, solved it by doing:
awk '{s += $9} END { print FILENAME, s/NR}' plink.356.assoc

Cheers, Ida
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top