- 通过while循环读取
通过shell脚本执行
$ cat test.txt
apple 1
banana 2
chery 3
$ cat myread.sh
while read line
do
echo $line
done < test.txt
$ sh myread.sh
apple 1
banana 2
chery 3
或者直接在命令行执行while命令(写在一行需要使用分号;来区分代码块)
$ while read line; do echo $line; done < test.txt
apple 1
banana 2
chery 3
- 通过awk命令
$ awk '{print $0}' test.txt //$0为当前完整行内容