[Ubuntu-zh] 如何在保留源文件格式(空格、制表符等)的条件下,读取文件

san xbapj1在gmail.com
星期五 九月 28 09:38:22 UTC 2012


这样

#!/bin/bash

idx=1
infile=$1
while read line
do
   line=$(sed -n ${idx}p $infile)
   echo "$line"
   let "idx+=1"
done <$infile



在 2012-09-28五的 17:20 +0800,gleerat写道:
> #!/bin/bash
> 
> infile=$1
> while read line
> do
>     echo $line
> done <$infile
> 
> 输出后删了空格
> 
> mts在ubuntu-unity:~/vasp/Cu-NH3/ads/NH3/100$ ./test.sh ppp
> 1.25449250 1.25449250 0.00000000
> 1.25449250 3.76347750 0.00000000
> 3.76347750 1.25449250 0.00000000
> 3.76347750 3.76347750 0.00000000
> 0.00000000 0.00000000 5.53328950
> 0.00000000 2.50898500 5.53328950
> 
> 试过了网上很多的方法,但是都不能保留源文件中的空格。
> 请问,如何保留源文件的格式,使输出与源文件一模一样呢?
> 源文件为
> 
>        1.25449250    1.25449250    0.00000000
>        1.25449250    3.76347750    0.00000000
>        3.76347750    1.25449250    0.00000000
>        3.76347750    3.76347750    0.00000000
>        0.00000000    0.00000000    5.53328950
>        0.00000000    2.50898500    5.53328950
> -------------- 下一部分 --------------
> 一个HTML附件被移除...
> URL: <https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20120928/427de1f3/attachment.html>





关于邮件列表 ubuntu-zh 的更多信息