Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 循环遍历扩展文件并使用每列作为输入_Bash_File_Input - Fatal编程技术网

Bash 循环遍历扩展文件并使用每列作为输入

Bash 循环遍历扩展文件并使用每列作为输入,bash,file,input,Bash,File,Input,我想运行一个需要三个输入的软件。当我在集群上运行分析时,我可以使用Slurm获取每一列作为作业数组的输入 samplesheet="test.txt" name=`sed -n "$SLURM_ARRAY_TASK_ID"p $samplesheet | awk '{print $1}'` foward=`sed -n "$SLURM_ARRAY_TASK_ID"p $samplesheet | awk '{print $2}'`

我想运行一个需要三个输入的软件。当我在集群上运行分析时,我可以使用Slurm获取每一列作为作业数组的输入

samplesheet="test.txt"
name=`sed -n "$SLURM_ARRAY_TASK_ID"p $samplesheet |  awk '{print $1}'`
foward=`sed -n "$SLURM_ARRAY_TASK_ID"p $samplesheet |  awk '{print $2}'`
reverse=`sed -n "$SLURM_ARRAY_TASK_ID"p $samplesheet |  awk '{print $3}'`
然后我可以使用以下命令运行软件:

software --imput $foward $reverse --output $name
它适用于作业数组。我想在我的电脑上做类似的事情。 例如,我有一个文件:

sample001   file001a  file001b
.
.
.
sample1000  file1000a  file1000b
第一列是输出文件的前缀,第1列和第2列是两个输入文件

我曾尝试使用循环或xargs,但它只适用于一列。 例如:

比如说,

for line in test.txt
do
     # do something with $line here
done


如何执行此操作?

对于类似的内容,最好在while循环中使用read,例如:

#/bin/bash
行数=0
读行时;做
行数=$((行数+1))
第1部分=$(回音$行|切割-d'-f1)
第2部分=$(回声$线|切割-d'-f2)
第三部分=$(回音$行|切割-d'-f3)
回显“行${Line_num}第1部分:${Part_1}第2部分:${Part_2}第3部分:${Part_3}”

完成<如果我正确理解您的需求,请尝试:
,同时读取-r name正向反向;执行echo软件--输入“$forward”“$reverse”--输出“$name”;完成
。是的,正是我想做的。非常感谢。
cat test.txt | while read line 
do
   # do something with $line here
done
sample001   file001a  file001b
sample002   file002a  file002b
sample003   file003a  file003b
sample004   file004a  file004b
sample005   file005a  file005b
sample006   file006a  file006b
sample007   file007a  file007b
sample008   file008a  file008b
sample009   file009a  file009b
sample010   file010a  file010b
$ ./read-from-file.sh 
Line 1 Part 1: sample001 Part 2: file001a Part 3: file001b
Line 2 Part 1: sample002 Part 2: file002a Part 3: file002b
Line 3 Part 1: sample003 Part 2: file003a Part 3: file003b
Line 4 Part 1: sample004 Part 2: file004a Part 3: file004b
Line 5 Part 1: sample005 Part 2: file005a Part 3: file005b
Line 6 Part 1: sample006 Part 2: file006a Part 3: file006b
Line 7 Part 1: sample007 Part 2: file007a Part 3: file007b
Line 8 Part 1: sample008 Part 2: file008a Part 3: file008b
Line 9 Part 1: sample009 Part 2: file009a Part 3: file009b
Line 10 Part 1: sample010 Part 2: file010a Part 3: file010b