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!

Extract characters

Status
Not open for further replies.

santhas

Technical User
Aug 27, 2003
35
AU
Hi Gurus,

I am trying to separate char and numeric values from ex 12G in an awk script.
I want to convert 12G to 24g ( 12*2)g.Any clues pl?

Thanks
 
Here is an awk solution, but its kind of clunky:

Code:
awk '
        {
                line=$0
                newline=""
                while(match(line,"[0-9]+")) {
                        newline=newline substr(line,1,RSTART-1) substr(line,RSTART,RLENGTH)*2
                        line=substr(line,RSTART+RLENGTH)
                }
                print newline line
        }
'

A much neater perl solution:

Code:
perl -pe '$_ =~ s/(\d+)/$1*2/eg;'

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top