• Rob's side project: I recently started Gun-Forums.com and we currently have a $100 raffle - if you're into guns, join up and enter the raffle to win $100.00. Gun Forums

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
 


O

old_bolvan

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


Members online


Latest posts

Top