我在文件上使用以下命令來根據 chr#(不同的染色體編號)提取幾行。這只是正在處理的一個文件。我有8 個這樣的文件,對於每個文件,我必須對chr 執行此操作(1 到22,然後是chrX 和chrY),我沒有使用任何循環,我單獨執行此操作,但如果您看到我希望標頭完好無損我的每一個輸出。如果我單獨執行,我會在輸出中得到標頭,但如果正在運行,但如果我一起運行所有8 個檔案的腳本(就像腳本中一個接一個的8*24 命令),則輸出沒有任何標頭。你能告訴我為什麼會發生這種情況嗎?
#!/bin/sh
#
#$ -N DOC_gatk_chr
#$ -cwd
#$ -e err_DOC_gatk_chr.txt
#$ -o out_DOC_gatk_chr.txt
#$ -S /bin/sh
#$ -M [email protected]
#$ -m bea
#$ -l h_vmem=25G
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr1" > S_313_IPS_S7995.chr1.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr2" > S_313_IPS_S7995.chr2.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr3" > S_313_IPS_S7995.chr3.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr4" > S_313_IPS_S7995.chr4.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr5" > S_313_IPS_S7995.chr5.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr6" > S_313_IPS_S7995.chr6.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr7" > S_313_IPS_S7995.chr7.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr8" > S_313_IPS_S7995.chr8.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr9" > S_313_IPS_S7995.chr9.coverage
我正在使用 qsub 將其作為作業運行,因此腳本的結構如下所示。如果我單獨執行命令,它會起作用,但如果我像這樣運行它們,標題不會列印在輸出檔案中,即“;”似乎不被認可。我嘗試使用 qsub filename.sh 和 sh filename.sh 來運行它。我發現使用 sh filename.sh 標題會列印在控制台中。所以肯定是';'之前的命令文件中未寫入分號。我怎樣才能擺脫這個問題。
期望的輸出:
Target total_coverage average_coverage IPS_S7995_total_cvg IPS_S7995_mean_cvg IPS_S7995_granular_Q1 IPS_S7995_granular_median IPS_S7995_granular_Q3 IPS_S7995_%_above_15
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
但我得到的輸出低於沒有標題的情況
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
答案1
你需要這樣的東西:
{ head -n1 S_313_IPS_S7995.coverage.sample_interval_summary;
grep "chr1" S_313_IPS_S7995.coverage.sample_interval_summary; } >S_313_IPS_S7995.chr1.coverage
或者
awk 'NR==1 || /chr1/' S_313_IPS_S7995.coverage.sample_interval_summary >S_313_IPS_S7995.chr1.coverage
問題是重定向僅影響一個命令。為了獲得重定向中head
和的輸出,必須將它們分組。grep
但awk
這裡可能是更好的選擇。