读取两个文件系在一个while循环 [英] Reading lines from two files in one while loop
本文介绍了读取两个文件系在一个while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件,其中包含 file1.csv
:
I have a file, file1.csv
containing:
This
is
some
text.
我使用同时读取行
循环通过每一行,例如:
I am using while read line
to cycle through each line, e.g.:
while read line; do
echo $line
done < file1.csv
我有另外一个文件,使用相同数量的行,名为 file2.csv
:
A
B
C
D
每一行对应于数据在同一行号码的第一个文件中的数据。
The data each line corresponds to data in the first file of the same line number.
- 如何修改while循环,这样使得它可以打印从
file2.csv
? 相应的行
- How can I modify the while loop, such so that it can print the corresponding line from
file2.csv
?
推荐答案
使用另一种FD。
while read line; do
if ! read -u 3 line2
then
break
fi
echo "$line***$line2"
done < file1.csv 3< file2.csv
这篇关于读取两个文件系在一个while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文