我想要实现的是:
1.逐行读取文件。2.将每个内容放入一个变量中(在EOF处停止,这里的问题是我不知道有多少行)3.在另一个文件中分开使用变量。
示例文件:
输出文件
这可能吗?
> while IFS=$'\n' read -r v1 v2 v3 v4 v5 v6 v7; do
> # put each new line a var
> echo "this is $v1" >>log.txt
> echo "this is $v2" >>log.txt
> etc.. ;
>
> done
该mapfile
命令在这里很有用:它将文件读入数组,每一行都是一个数组元素:
mapfile -t lines < filename
for line in "${lines[@]}"; do
echo "this is $line"
done
参考:http : //www.gnu.org/software/bash/manual/bashref.html#index-mapfile
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句