0

I have the following file ( example of typical file.txt )

remark - parameters are with different length

     param1=353
     param2=726
     param3=75.32
     param4=21.03
     number100=234
     arg1=100
     the_last_number=true
     x=55
     .
     .
     .

How to translate file.txt to the following format: ( by printf or other solution that can be part of my bash script)

   1  param1.....................353
   2  param2.....................726
   3  param3.....................75.32
   4  param4.....................21.03
   5  number100..................234
   6  agr1.......................100
   7  the_last_number............true
   8  x..........................55
     .
     .
     .

3 Answers3

2
while read -r line
do
    printf '%s\n' "${line/=/........}"
done < inputfile
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • 2
    @Eytan: Well, now it really is a duplicate of the question I linked to in my comment attached to your question. – Dennis Williamson Jun 16 '12 at 20:45
  • hi Dennis , I am not understand how your previous solution http://stackoverflow.com/questions/4409399/padding-characters-in-printfcan answer on my question? , I not want to insert the parameters in the bash script or any character from file.txt in the bash script , the target is to print the text file as my example in my question –  Jun 17 '12 at 07:38
  • @Eytan: See fgm's answer. It's a variation on my answer at that link which is applicable to your data. – Dennis Williamson Jun 17 '12 at 10:40
0

This shoudl work.

SC=$(cat<<ENDDOC
if(~/(.*)=(.*)/){print "\$1"."."x(32-length(\$1))."\$2\n";}
else{print;}
ENDDOC)
perl -n -e "$SC" < file.txt
pizza
  • 7,296
  • 1
  • 25
  • 22
0

Another one:

no=0
fill='....................'                     # e.g. 20 points
while IFS='=': read left right ; do
  printf "%4d  %s%s%s\n" $((++no)) $left ${fill:${#left}} $right
done < "$infile"

Output:

   1  param1..............353
   2  param2..............726
   3  param3..............75.32
   4  param4..............21.03
   5  number100...........234
   6  arg1................100
   7  the_last_number.....true
   8  x...................55
Fritz G. Mehner
  • 16,550
  • 2
  • 34
  • 41
  • hi fgm last question how to numers the lines - see my update in my question ? –  Jun 17 '12 at 11:51