如何循环遍历 bash linux 中的两列

How to do a loop through two columns in bash linux

我是 bash linux 编码新手。基本上我想使用包含两列的文本文件进行循环。

对于单列文件,我使用这种类型的代码:

for element in `cat /path/file.txt | tr -d '\r'`
do
operation on element
done

我想使用每行的两个元素作为函数的参数。所以它会像:

file.txt:

Column A Column B
a c
b d

并且在同一行代码中使用 A 列和 B 列的第一行,然后是第二行并继续...

我不知道是否可以使用索引来指定每次迭代所需的行和列。

看起来你想要:

tr -d '\r' < /path/file.txt | 
while read a b; do
  operate "$a" "$b"
done