Apr 17, 2002 #1 hmehta IS-IT--Management Jun 5, 2002 27 US I have a file with phone nos 9728993456 as the first filed. I need to split inoo 972-899-3456 . How can I do it in awk.
I have a file with phone nos 9728993456 as the first filed. I need to split inoo 972-899-3456 . How can I do it in awk.
Apr 17, 2002 #2 marsd IS-IT--Management Apr 25, 2001 2,218 US awk ' { if (length($1) == 10 && $1 ~ /[0-9]+/) { cnt++ numbers["area", NR] = substr($1,1,3) "-" numbers["prefixes", NR] = substr($1,4,6) "-" numbers["spec", NR] = substr($1,7,10) } for (xx in numbers) { for (m=1 ; m <= cnt ; m++) { if (xx ~ m) { printf "%s", numbers[xx] }; }; } }' file Might work, not tested. Upvote 0 Downvote
awk ' { if (length($1) == 10 && $1 ~ /[0-9]+/) { cnt++ numbers["area", NR] = substr($1,1,3) "-" numbers["prefixes", NR] = substr($1,4,6) "-" numbers["spec", NR] = substr($1,7,10) } for (xx in numbers) { for (m=1 ; m <= cnt ; m++) { if (xx ~ m) { printf "%s", numbers[xx] }; }; } }' file Might work, not tested.
Apr 18, 2002 1 #3 bigoldbulldog Programmer Feb 26, 2002 286 US These work well... awk '{ print substr($0,1,3) "-" substr($0,4,3) "-" substr($0,7,4) }' file sed 's/\(.\{3\}\)\(.\{3\}\)/\1-\2-/' file sed 's/\(...\)\(...\)/\1-\2-/' file The last one runs the fastest. Cheers, ND Upvote 0 Downvote
These work well... awk '{ print substr($0,1,3) "-" substr($0,4,3) "-" substr($0,7,4) }' file sed 's/\(.\{3\}\)\(.\{3\}\)/\1-\2-/' file sed 's/\(...\)\(...\)/\1-\2-/' file The last one runs the fastest. Cheers, ND
Apr 18, 2002 Thread starter #4 hmehta IS-IT--Management Jun 5, 2002 27 US Thanks a lot guys... Upvote 0 Downvote