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
     .
     .
     .
2

3 Answers 3

2
while read -r line
do
    printf '%s\n' "${line/=/........}"
done < inputfile
Sign up to request clarification or add additional context in comments.

3 Comments

@Eytan: Well, now it really is a duplicate of the question I linked to in my comment attached to your question.
hi Dennis , I am not understand how your previous solution stackoverflow.com/questions/4409399/… 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
@Eytan: See fgm's answer. It's a variation on my answer at that link which is applicable to your data.
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

1 Comment

hi fgm last question how to numers the lines - see my update in my question ?
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

1 Comment

Sorry, but that is one of the ugliest things I've ever seen.