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!

Addition

Status
Not open for further replies.

whatisthis987

IS-IT--Management
Apr 24, 2007
34
US
Hi,
I have a file that looks like this:

textxxxxxx abc 100 200
text again.....300 100
more text......
(5853.2775,2960.825)
(5853.275, 2960.82) (5853.28, 2960.83)
(6185.3225,6330.975)
(6185.32, 6330.97) (6185.325, 6330.98)

I would like to add 10 to the numbers of the lines without any texts (the ones in quotes). Meaning the output should be
textxxxxxx abc 100 200
text again.....300 100
more text......
(5863.2775,2970.825)
(5863.275, 2970.82) (5863.28, 2970.83)
(6195.3225,6340.975)
(6195.32, 6340.97) (6195.325, 6340.98)

Anyone please help?
 
Here is a solution which unfortunately loses some precision in the output due to awk's printf defaulting to 2 decimal places. You could work around this by changing it to always use, say, 4 decimal places, or, if you need them to be exactly the same length as the input data, calculate the appropriate length to use and insert it into the printf format string.

Code:
awk '
        /[[:alpha:]]/ { print ; next }
        {
                rest=$0
                while (match(rest,"[0-9.]+")) {
                        printf "%s",substr(rest,1,RSTART-1) substr(rest,RSTART,RLENGTH)+10
                        rest=substr(rest,RSTART+RLENGTH)
                }
                print rest
        }
' inputfile

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top