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!

Sub puts 1 or 0 at end of each line, I don't want it. Help!

Status
Not open for further replies.

Draley

Technical User
Jul 3, 2002
2
US
Okay, my input file looks like this:
machine 192.168.1.26
login yourname
password password

My script looks like this:
{
print $0 sub(/192.168.1.26/, "0.0.0.0") > file
}

My output is this:
machine 0.0.0.0 1
login yourname0
password password0

Is there any way I can get it to use the sub without adding the extra numbers (1 and the 0's at the end of the lines) to be omitted?
 
sub is returning 1 for success or 0 for failure and it goes out on the printed line after $0. The $0 is changed by sub before printing.

just change to

{
sub(/192.168.1.26/, "0.0.0.0")
print $0 > file
} Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
For as simple as awk is (even I understand some of it, c'mon!!!) I knew it was something simple like that. Thanks TONS.

--Dustin Raley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top