Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux printf+;bash脚本_Linux_Bash_Printf - Fatal编程技术网

Linux printf+;bash脚本

Linux printf+;bash脚本,linux,bash,printf,Linux,Bash,Printf,我有以下文件(典型file.txt的示例) 备注-参数具有不同的长度 param1=353 param2=726 param3=75.32 param4=21.03 number100=234 arg1=100 the_last_number=true x=55 . . . 如何将file.txt转换为以下格式:(通过printf或可以作为我的bash脚本一部分的其他解决方案) 读取时

我有以下文件(典型file.txt的示例)

备注-参数具有不同的长度

     param1=353
     param2=726
     param3=75.32
     param4=21.03
     number100=234
     arg1=100
     the_last_number=true
     x=55
     .
     .
     .
如何将file.txt转换为以下格式:(通过printf或可以作为我的bash脚本一部分的其他解决方案)

读取时-r行
做
printf“%s\n”${line/=/…}
完成<输入文件
这应该行得通

SC=$(cat<<ENDDOC
if(~/(.*)=(.*)/){print "\$1"."."x(32-length(\$1))."\$2\n";}
else{print;}
ENDDOC)
perl -n -e "$SC" < file.txt
SC=$(cat另一个:

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"

@Eytan的可能重复:好吧,现在它实际上是我在你问题的评论中链接到的问题的重复。嗨,丹尼斯,我不明白你以前的解决方案如何回答我的问题?我不想在bash脚本中插入参数或bash脚本中file.txt中的任何字符,目标是打印t他将文本文件作为我的示例question@Eytan:查看fgm的答案。这是我在该链接上的答案的变体,适用于您的数据。对不起,这是我见过的最丑陋的事情之一。嗨,fgm最后一个问题如何计算行数-请参阅我问题中的更新?
SC=$(cat<<ENDDOC
if(~/(.*)=(.*)/){print "\$1"."."x(32-length(\$1))."\$2\n";}
else{print;}
ENDDOC)
perl -n -e "$SC" < file.txt
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"
   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