使用bash一行读取线和保持空间 [英] Use bash to read line by line and keep space

查看:74
本文介绍了使用bash一行读取线和保持空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用猫TEST.FILE,它会显示

  1
 2
  3
   4

当我使用bash的文件,

 猫TEST.FILE |
同时读取数据

    回声$ DATA
DONE

它会显示

  1
2
3
4

我如何才能让结果就像原来的测试文件?


解决方案

  IFS =''
猫TEST.FILE |
同时读取数据

    回声$ DATA
DONE

我知道你可能已经从简单的东西,确实需要一个管道的例子,但在此之前别人说的:

  IFS =''
同时读取数据;做
    回声$ DATA
完成< TEST.FILE

When I use "cat test.file", it will show

1
 2
  3
   4

When I use the bash file,

cat test.file |
while read data
do
    echo "$data"
done

It will show

1
2
3
4

How could I make the result just like the original test file?

解决方案

IFS=''
cat test.file |
while read data
do
    echo "$data"
done

I realize you might have simplified the example from something that really needed a pipeline, but before someone else says it:

IFS=''
while read data; do
    echo "$data"
done < test.file

这篇关于使用bash一行读取线和保持空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆