shell 中的 for 循环从制表符分隔文件的列名中获取输入
for loop in shell taking input from column name of a tab delimited file
我想对一堆相似的文件执行迭代任务,这些文件的相似部分文件名包含“{$ID}”。该程序为每个单独的文件手动 运行。我想在 shell 中编写一个 for 循环以从 txt 文件中获取 'ID' 并执行任务。我无法根据 test.txt 文件的 coloumn1 中的值在 for 循环中给出输入参数 ID
例如:
for ID in 'values in coloumn1 of test.txt file'
do
file1=xyz_{$ID}.txt
file2=abc_{$ID}.txt
execute the defined function using file1 and file2
write to > out_{$ID}.txt
done
使用 while
循环遍历文件,让 read
从文件中输入一行并将第一列从每一行中拆分出来。
while read -r ID rest; do
...
done < test.txt
如果列由空格以外的字符分隔,请使用 IFS
指定单个字符。
# comma-delimited files
while IFS=, read -r ID rest; do
...
done < test.txt
我想对一堆相似的文件执行迭代任务,这些文件的相似部分文件名包含“{$ID}”。该程序为每个单独的文件手动 运行。我想在 shell 中编写一个 for 循环以从 txt 文件中获取 'ID' 并执行任务。我无法根据 test.txt 文件的 coloumn1 中的值在 for 循环中给出输入参数 ID 例如:
for ID in 'values in coloumn1 of test.txt file'
do
file1=xyz_{$ID}.txt
file2=abc_{$ID}.txt
execute the defined function using file1 and file2
write to > out_{$ID}.txt
done
使用 while
循环遍历文件,让 read
从文件中输入一行并将第一列从每一行中拆分出来。
while read -r ID rest; do
...
done < test.txt
如果列由空格以外的字符分隔,请使用 IFS
指定单个字符。
# comma-delimited files
while IFS=, read -r ID rest; do
...
done < test.txt