我.csv
在名为 的目录中有多个文件mydirectory
。我想首先使用一些 bash/awk/sed 命令根据LeftChr
列对所有这些文件进行排序,然后根据RightChr
列并获取result
.
>Id LeftChr LeftPosition LeftStrand LeftLength RightChr RightPosition RightStrand
1979 chr1 825881 - 252 chr2 5726723 -
5480 chr2 826313 + 444 chr2 5727501 +
5492 chr5 869527 + 698 chr2 870339 +
1980 chr2 1584550 - 263 chr1 1651034 -
5491 chr14 1685863 + 148 chr1 1686679 +
5490 chr1 1691382 + 190 chr1 1693020 +
结果
>Id LeftChr LeftPosition LeftStrand LeftLength RightChr RightPosition RightStrand
5490 chr1 1691382 + 190 chr1 1693020 +
1979 chr1 825881 - 252 chr2 5726723 -
1980 chr2 1584550 - 263 chr1 1651034 -
5480 chr2 826313 + 444 chr2 5727501 +
5492 chr5 869527 + 698 chr2 870339 +
5491 chr14 1685863 + 148 chr1 1686679 +
答案1
你基本上只需要“sort -k”
for f in *.csv; do
# output of first line
head -1 $f
# output of any but first line, then sort after 2. then 6. column
tail -n +2 $f | sort -k 2,6
done