Create a fixed-length strings

P

papori

Guest
Hi guys,
I have a file containing different lengths of strings.
I want all of them to be in the same length. For example 10 characters.
Most of them are already in this length, so I want to fix those that are less than 10 to 10 by padding.
for example,

1234567890
1234567890
12345678
1234567890

so, I want the third string to be:
12345678NN

The others are OK, so I don't want to touch them..

Any idea of doing it in a simple way?
sed or awk ?

Thanks,
Pap
 


Code:
perl -ni.bak -e 'chomp; printf "%.10s%s\n", $_, "N"x(10-length)' file.txt
 

Members online


Top