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

replace "10.10.20.[1-8] 80" with "10.10.20.9 8[*]" in record

Status
Not open for further replies.

dbad

IS-IT--Management
Jul 29, 2002
3
NZ

I'm parsing some logs and need to replace a string with a wildcard match with another string, while still maintaining the 'wildcard'.

e.g.
line: blah1 blah2 10.10.20.1 80 blah5 blah6
needs to look like;
line: blah1 blah2 10.10.20.9 81 blah5 blah6

(delimited by space, would prefer not to rip into fields)

where the '1' may be from 1 to 8 in value. I don't want to parse the file EIGHT times to replace possible occurances, and feel that AWK may be just the ticket.

How do you refer to a 'wildcard' match for value as positional in the output condition?

eg s/10.10.20.[1-8] 80/10.10.20.9 8[*]/

I've got the code for SQLS replace substitution (single update), but the db logging is now too expensive.

Your help is much appreciated.

 
Something like:

if ($3 ~ / 10.10.20.[1-8]/) {
fldnum = substr($3,10,1)
sub(fldnum,"9",$3)
#confused here:either you want this?
$4 = substr($4,1,1) fldnum
#or you want this?
$4 = $4 + 1
}

Good Luck
 
Ta muchly, just what I needed...

I've ended up with;

{
if ($3 ~ /10.10.20.[1-8]/) {
fldnum = substr($3,10,1)
$3 = substr($3,1,9) "9"
$4 = substr($4,1,1) fldnum
}
print $0
}

Works a treat...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top