Shell 在行尾用n个空格填充文件

Shell 在行尾用n个空格填充文件,shell,unix,sh,padding,aix,Shell,Unix,Sh,Padding,Aix,我有一个文件,看起来像下面的格式。我想在行尾加上空格 File1.txt Steve Smith Thomas Muller Tim Cook Bill Gates 我已经使用了下面的命令,但它没有给我想要的输出,它正在分裂为 Steve Smith 然后给出输出 while read line; do printf "%-20s\n" $line; done < file1.txt 引用变量行,最好使用read-r: while read -r line; do printf

我有一个文件,看起来像下面的格式。我想在行尾加上空格

File1.txt

Steve Smith
Thomas Muller
Tim Cook
Bill Gates
我已经使用了下面的命令,但它没有给我想要的输出,它正在分裂为

Steve 
Smith 
然后给出输出

while read line; do printf "%-20s\n" $line; done < file1.txt

引用变量
,最好使用
read-r

while read -r line; do printf "%-20s\n" "$line"; done < file1.txt
读取-r行时
;不打印“%-20s\n”“$line”;完成
测试:

读取-r行时
;不打印“%-20s\n”“$line”;完成
帮助阅读
说明:
-r不允许反斜杠转义任何字符
。对于您的情况,可能不需要它,但拥有它总是很好的。
while read -r line; do printf "%-20s\n" "$line"; done < file1.txt
while read -r line; do printf "%-20s\n" "$line"; done < file1.txt | cat -vte
Steve Smith         $
Thomas Muller       $
Tim Cook            $
Bill Gates          $