Hi Everyone,
I need to increment a value in the fixed length file. The file has almost a million rows. Is there any easy way to accomplish this.
Ex
input file
ASDSD ADSD 00000 X
AAASD ADSD 00000 X
SDDDD ADSD 00000 X
Ouput
ASDSD ADSD 00001 X
AAASD ADSD 00002 X
SDDDD ADSD 00003 X
Thanks in advance.
RudiC
August 6, 2014, 2:21pm
2
Please use code tags as required by forum rules!
I don't think you can fit a million into 6 decimal digits.
Sorry about that RudiC. Those are not decimal values in the file and I did not provide no of positions and it should have been 7 digits. The sample value more precisely
ASDSD ADSD 0000000 X
AAASD ADSD 0000000 X
SDDDD ADSD 0000000 X
output
ASDSD ADSD 0000001 X
AAASD ADSD 0000002 X
SDDDD ADSD 0000003 X
RudiC
August 6, 2014, 2:46pm
4
Please use code tags, not icode tags.
Try
awk '{$3=sprintf ("%07.f", NR)}1' file
ASDSD ADSD 0000001 X
AAASD ADSD 0000002 X
SDDDD ADSD 0000003 X
Hi Rudic,
I have tried the command but the length of the file is modified everytime I run the command. For ex
ASDSD ADSD 0000001 X
AAASD ADSD 0000001 X
SDDDD ADSD 0000001 X
Modified to
ASDSD ADSD 0000001 X
AAASD ADSD 0000002 X
SDDDD ADSD 0000003 X
if column 3 value is constant, use below code
awk '{newnum=sprintf ("%07.f", NR);sub("0000001",newnum,$0)}1' filename
RudiC
August 7, 2014, 4:38am
7
That is not what you gave us as a sample file.
Hi Rudi/Pravin,
Sorry the length was wrong in the first file and the I did try with the modified length and it worked fine.. Thank you so much.