1831665 Members
2141 Online
110029 Solutions
New Discussion

sed

 
SOLVED
Go to solution
Rpger Tavener
Occasional Advisor

sed

I have a sequential file that has variable length records in it. I would like to add spaces to the end of each record to make the total record length = 1123 by adding spaces to the end of each record. Can this be done with sed?

Thanks
When the only tool you own is a hammer, every problem looks like a nail!
3 REPLIES 3
curt larson_1
Honored Contributor
Solution

Re: sed

i'm not to sure about using sed, but it should be quite easy with any utility that has a printf statement, awk, shell, perl, etc

awk:

cat file | awk '{
printf("%-1123s\n",$0);
}'

or in the shell

while read line
do
printf "%-1123s\n" $line
done
Sridhar Bhaskarla
Honored Contributor

Re: sed

Hi,

I liked Curt's idea.

awk '
{ if (length($0) > 1123) print $0 ;
else printf("%-1123s\n",$0) }' data2 > out


To make sure it doesn't truncate the records of length more than 1123.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Rpger Tavener
Occasional Advisor

Re: sed

Thanks ... Awk is what i needed..
When the only tool you own is a hammer, every problem looks like a nail!