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

change value in 2nd line of file using awk

Status
Not open for further replies.

nuzzy

MIS
Aug 16, 2001
42
US
Still trying to figure this awk stuff out! I'm confused about if the field you want to replace is on another line. For example I have a file named MMVer.r and in it is:

resource 'tver' (1000) {
"3.0a6"
};

How would I change the "3.0a6" to "3.0a7" then the next time I run the awk command, to 3.0a8 and so forth. Since the field is on the second line I'm not sure how??



 
Try something like this
Code:
/resource/ {    # find the resource line
   print        # print it
   getline      # "3.0a6" is now in $0
   # do some stuff
   print        # and print that as well
}

--
 
thanks, but I don't know what to do with that...
 
One way to run it is to put it in a file, nuzzy.awk say, and enter

awk -f nuzzy.awk MMVer.r > outfile

/resource/ { # find the resource line
print # print it
getline # "3.0a6" is now in $0
print substr($0,1,length-1) (substr($0,length)+1)
}

CaKiwi
 
Another way:

awk '
NR==2 {
match($0,"a[0-9]+")
n=substr($0,RSTART+1,RLENGTH-1)
$0=substr($0,1,RSTART) ++n substr($0,RSTART+RLENGTH)
}
{print}
' file1 > file2
 
thanks guys...I'll try it when I get to work. What I REALLY need to do is change the value inside MMVer.r without having to create another file. I'll be putting the awk/gawk command in a script and want it to just change the value of "3.0a6". I hope this makes sense. :)

P.S. - I'll need that a6 value to go higher than 10, i.e. a25...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top