Cailet
July 6, 2009, 11:00am
1
Hi all-
I've got a file that will have multiple columns. In one column there will be a string that is 10 digits in length, but I need to trim the first four zeros to make it 6 characters?
example:
0000001234
0000123456
0000234566
0000000321
output:
001234
123456
234566
000321
What scripting langauge are you using to process the file?
Try this,
sed 's/^....//g' <Filename>
I actually figured it out on my own ---
In case anyone has questions:
using korn shell
i just looped through with this: (the column is the third in the file)
while [ $i -le $recordcount ]; do
Current=`sed -n "$i p" $File | awk '{print substr($3,length($3)-5,6)}'`
i=$((i+1))
done
since I 'm also doing some other processing individually on each field this worked for me....
cailet:
I actually figured it out on my own ---
In case anyone has questions:
using korn shell
i just looped through with this: (the column is the third in the file)
while [ $i -le $recordcount ]; do
Current=`sed -n "$i p" $File | awk '{print substr($3,length($3)-5,6)}'`
i=$((i+1))
done
since I 'm also doing some other processing individually on each field this worked for me....
you don't to use that many constructs to trim 4 zeroes.
awk '{gsub(/^0000/,"")}1' file
another option is to use perl unpack/unpack to process fixed-width-format string.
while(<DATA>){
my($a,$b)=unpack('A4A6',$_);
print $b,"\n";
}
__DATA__
0000001234
0000123456
0000234566
0000000321