小编Eri*_*ric的帖子

从bash中的文本文件中读取多行

当我编写 shell 脚本时,我所做的大部分工作是将其他模块的 I/O 包装在 python、matlab 等中。为此,我通常使用文本文件或类似性质的输入/输出路径。我知道从我可以使用的一个文件中读取一行,

for file in $(cat $1);
do
    code using $file
done
Run Code Online (Sandbox Code Playgroud)

但是如果我想使用两个文件中的等效行做某事怎么办?类似于等效的Java:

while((line1 = file1.readLine()) != null) {
    line2 = file2.readLine();
    //do something with both lines...
}
Run Code Online (Sandbox Code Playgroud)

在 bash 中执行此操作的标准方法是什么?

shell bash text-processing

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

bash ×1

shell ×1

text-processing ×1