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

add 0 to empty line

Status
Not open for further replies.

smithia6

Technical User
Aug 28, 2002
35
0
0
US
Last question of the day folks.

I have the script running nice now where it adds up lines of data, however some lines of data look like this.

3.2
1.1
0.5

0.2
0.2
0.2

0.1

Notice some of the lines have no data what I need to do is to add a 0 to the empty lines, how can I do this??

Regards

Ian
 
Try this :
[tt]
awk '{print (NF ? $0 : 0)}' input_file
[/tt]

Jean Pierre.
 
Tried that and this is what I get

awk: syntax error near line 1
awk: illegal statement near line 1
 
Try nawk instead of awk

or
[tt]
awk '{if (NF) print $0; else print 0 }' input_file
[/tt]

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top