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!

How to find and delete row in file

Status
Not open for further replies.

bosoxer1

Programmer
Jan 22, 2005
20
0
0
US
I currently use the below script to modify a file, but I have to find a string starting in postion 37, like "19012", and delete that row, and continue with the rest of the script.

How do I NOT print that row out?

1==NR { print; next }
NR>2 { print fix(line) }
{line = $0}
END { print line }
function fix( s )
{ if (" "==substr(s,col,1) )
s = substr(s,1,col-1) "3" substr(s,col+1)
return s
}
 
Something like this ?
substr($0,37,5)=="19012"{next}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Great...I have the format, but should it be wrapped inside an if statement? I actually have to strings to look for and by pass...

substr($0,1,42)=="0000671960595 19012" {next}
substr($0,1,36)=="99994661 " {next}

Should they go before the function call?
 
They should go before this line:

[tt]NR>2 { print fix(line) }[/tt]

Every line of an awk programme contains an implicit if statement. Taking the above line as an example, you could read it like this:

[tt]if (NR > 2) then { print fix(line) }[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top