1830945 Members
2090 Online
110017 Solutions
New Discussion

A unix text reformat

 
SOLVED
Go to solution
Ferdi Castro
Advisor

A unix text reformat

Hi Everyone,

I would like to ask you assistance for re my text reformat.

I have fileA with this content

abcde,1,xyz
gjhkl,2,bhy
....
...
qwerty,99,mko

I wanna change all second column in same fixed number of characters (lets say just six digits there fore having leading zeroes for lower numbers) like

abcde,000001,xyz
gjhkl,000001,bhy
....
...
qwerty,000099,mko

Can I use the awk command? if yes kindly share it to me then I'll check it. thanks much.

Ferdi
2 REPLIES 2
Peter Godron
Honored Contributor
Solution

Re: A unix text reformat

Ferdi,

awk -F',' '{printf "%s,%06d,%s\n",$1,$2,$3}' text.lis

john korterman
Honored Contributor

Re: A unix text reformat

Hi,

you can use e few standard cammands, particularly the features of typeset, e.g.:

#!/usr/bin/sh
typeset -Z6 fup
IFS=","
while read one two three
do
fup="$two"
echo "$one,$fup,$three"
done <./infile

man ksh and check typeset!

regards,
John K.
it would be nice if you always got a second chance