Feb 12, 2008 #1 santhas Technical User Joined Aug 27, 2003 Messages 35 Location 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
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
Feb 12, 2008 #2 Annihilannic MIS Joined Jun 22, 2000 Messages 6,317 Location AU 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. Upvote 0 Downvote
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.