我想使用命令行对包含.coordinates.txt文件的文件夹多次运行Perl脚本,进行多次“操作”,并且最后一步,我想基于第一行值进行排序。我写的是:
for i in ./*gb.coordinates.txt; do perl myscript $i |
awk 'NR==1 {print $2,"\t***here"; next } 1'|sed '2d'| #the output has an empty line in the second row so I remove it and I add "\t***here" to have and idea about the first line value after my final sorting
if [[awk 'FNR == 1 && $1>0']] then {sort -k1nr} else {sort -k1n} fi
> $i.allvalues.txt;
done
直到这里:
for i in ./*gb.coordinates.txt; do perl myscript $i | awk 'NR==1 {print $2,"\t***here"; next } 1'|sed '2d' > $i.allvalues.txt; done
一切正常。
所以正如我在最后一步上面写的那样,我想要的是这样的一种:
if the first line of my output >=0 then sort -k1n else sort -k1nr
if condition
之前的输出是:
XXXX eiter positive number or negative \t***here
32
4455
-2333
23
-123
而且我希望我的输出像:
如果xxxx =正]
xxxx (going in the correct order) \t***here 4455 32 23 -123 -2333
如果xxxx =否定
xxxx (going in the correct order) \t***here -2333 -123 23 32 4455
所以我的问题是,我不知道该连接if语句和排序的对象。
我想使用命令行对包含.coordinates.txt文件的文件夹多次运行Perl脚本,进行多次“操作”,最后一步,我想基于第一个...进行排序。
无需使用awk
。将perl脚本的输出通过管道传递到shell块,该shell块读取第一行,测试它是肯定的还是否定的,然后调用适当的排序。