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!

i need help with awk to replace non-zero number with 0

Status
Not open for further replies.

mnnarendra

IS-IT--Management
Mar 24, 2008
3
US
This is the input file pwpem_b.ovr -

W25_2009295 1 46151.91
W26_2009594 1 24758.78
W26_2009595 1 46421.62


The non-numeric values starting position 50, length of 8 need to be replaced with 0 and followed by spaces as shown below. This should be the output file pwpem_a.ovr.

W25_2009295 1 0
W26_2009594 1 0
W26_2009595 1 0
 
Code:
awk '{print substr($0,1,48) "0       "}' inputfile > outputfile

Annihilannic.
 
Works great. I need the awk script to handle file with zero byte as well.

Thank you.
 
mnnarendra said:
I need the awk script to handle file with zero byte as well.

What do you mean? Does that solution not work for 0 byte files?

Annihilannic.
 
I understand, I've seen your other post in the Unix Scripting forum now.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top