我有一個包含文件的目錄編號這樣文件進行排序,然後對他們中的每一個
1>chr1:2111-1111_mask.txt
1>chr1:2111-1111_mask2.txt
1>chr1:2111-1111_mask3.txt
2>chr2:345-678_mask.txt
2>chr2:345-678_mask2.txt
2>chr2:345-678_mask3.txt
100>chr19:444-555_mask.txt
100>chr19:444-555_mask2.txt
100>chr19:444-555_mask3.txt
每個文件都包含像在第一線>chr1:2111-1111
的名稱,並在第二一系列字符的執行命令線。 我需要使用>
之前的數字作爲參考,在數字上對此目錄中的文件進行排序,對_mask3
中的每個文件執行命令並使用。
我有這樣的代碼
ls ./"$INPUT"_temp/*_mask3.txt | sort -n | for f in ./"$INPUT"_temp/*_mask3.txt
do
read FILE
Do something with each file and list the results in output file including the name of the string
done
它的工作原理,但是當我檢查輸出文件中的字符串列表,他們都是這樣
>chr19:444-555
>chr1:2111-1111
>chr2:345-678
爲什麼呢?
您最好不要將'>'字符作爲文件名的一部分。在處理名稱錯誤的地方,它被解釋爲一個命令而不是文件名,'> chr19:444-555'會將'chr19:444-555'截斷爲'0'或將stdin中的任何內容重定向到文件' chr19:444-555' –
[你不應該爲你的腳本解析'ls']的輸出(http://mywiki.wooledge.org/ParsingLs),對於初學者!不知道在這種情況下替代是什麼。 – miken32