我是 bash linux 編碼的新手。基本上我想使用具有兩列的文本檔案進行回圈。
對于單列檔案,我使用這種型別的代碼:
for element in `cat /path/file.txt | tr -d '\r'`
do
operation on element
done
我想使用每行的兩個元素作為函式的引數。所以它會像:
檔案.txt:
| A欄 | B欄 |
|---|---|
| 一種 | C |
| b | d |
并在同一行代碼中使用 A 列和 B 列的第一行,然后是第二行并繼續......
我不知道是否可以使用索引來為每次迭代指定我想要的行和列。
uj5u.com熱心網友回復:
看起來你想要:
tr -d '\r' < /path/file.txt |
while read a b; do
operate "$a" "$b"
done
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/455972.html
