2015-04-30 108 views
1

在下面的bash中,打開程序時下載文件,然後根據用戶輸入搜索該文件,並將結果寫入新文件。截至目前,文件下載和用戶被提示輸入,但輸入後沒有任何反應。bash根據用戶輸入搜索文件並創建新文件

例如,打開bash並下載download.txt,然後用戶輸入id(NA04520)。該id用於搜索download.txt,並將該行寫入match.txt。代碼運行但沒有輸出結果。最終,我會搜索id中找到的特定文本,但我認爲基於用戶輸入的搜索是一個好的開始。謝謝 :)。

#!/bin/bash 

cd 'C:\Users\cmccabe\Desktop\wget' 
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv --progress=bar:force 2>&1 | tail -f -n +6 
{ 
printf "\n\n" 
printf "What is the id of the NGS patient: "; read id 
    [ -z "$id" ] && printf "\n No ID supplied. Leaving match function." && sleep 2 && return 
    [ "$id" = "end" ] && printf "\n Leaving match function." && sleep 2 && return 
} 


input=$id  
while read -r line 
do 
case $line in 
    *$id*) 
     echo $line " yes" >> bashgrep.txt 
     ;; 
    *) 
      echo "no" 
      ;; 
esac 
done 

download.txt

Report,Status,Flows,Library,TF Name,Q10 Mean,Q17 Mean,System SNR,50Q10  Reads,50Q17 Reads,Keypass Reads,TF Key Peak Counts,Total_Num_Reads,Library_50Q10_Reads,Library_100Q10_Reads,Library_200Q10_Reads,Library_Mean_Q10_Length,Library_Q10_Coverage,Library_Q10_Longest_Alignment,Library_Q10_Mapped Bases,Library_Q10_Alignments,Library_50Q17_Reads,Library_100Q17_Reads,Library_200Q17_Reads,Library_Mean_Q17_Length,Library_Q17_Coverage,Library_Q17_Longest_Alignment,Library_Q17_Mapped Bases,Library_Q17_Alignments,Library_50Q20_Reads,Library_100Q20_Reads,Library_200Q20_Reads,Library_Mean_Q20_Length,Library_Q20_Coverage,Library_Q20_Longest_Alignment,Library_Q20_Mapped Bases,Library_Q20_Alignments,Library_Key_Peak_Counts,Library_50Q47_Reads,Library_100Q47_Reads,Library_200Q47_Reads,Library_Mean_Q47_Length,Library_Q47_Coverage,Library_Q47_Longest_Alignment,Library_Q47_Mapped Bases,Library_Q47_Alignments,Library_CF,Library_IE,Library_DR,Library_SNR,Raw Accuracy,Sample,Notes,Run Name,PGM Name,Run Date,Run Directory,Num_Washouts,Num_Dud_Washouts,Num_Washout_Ambiguous,Num_Washout_Live,Num_Washout_Test_Fragment,Num_Washout_Library,Library_Pass_Basecalling,Library_pass_Cafie,Number_Ambiguous,Nubmer_Live,Number_Dud,Number_TF,Number_Lib,Number_Bead,Library_Live,Library_Keypass,TF_Live,TF_Keypass,Keypass_All_Beads,P,s 
Auto_user_MOL-95-Epilepsy70_125,Completed,500,hg19,TF_A,93.0,90.0,27.4077550007,27969.0,27031.0,28647.0,93.0,5046334,4861480,4439577,2307648,179,0.0,343,885197150,4942977,4689944,4272916,2213442,177,0.0,341,850800392,4796942,4465846,4082874,2050257,171,0.0,341,804445593,4698861,81.0,4073847,3251302,1186042,143,0.0,319,651683806,4541746,0.515698455274,0.728147709742,0.00734527275199,21.2101955615,99.4,NA04520,NA04520,R_2014_01_14_16_21_42_user_MOL-95-Epilepsy70,MolecularGenetics,2014-01-14 22:21:42+00:00,/results/MolecularGenetics/R_2014_01_14_16_21_42_user_MOL-95-Epilepsy70,0,0,0,0,0,0,0,0,0,9332288,14179,31491,9300797,9346467,0,0,9332288,0,0,"{""variantCaller"": {""hotspots"": {}, ""barcoded"": ""false"", ""Target Regions"": ""Epilepsy70"", ""Trim Reads"": true, ""Target Loci"": ""Not using"", ""variants"": {""no_call"": 0, ""homo_snps"": 50, ""het_snps"": 104, ""other"": 0, ""variants"": 163, ""het_indels"": 3, ""homo_indels"": 6}, ""Configuration"": ""Germ Line - Low Stringency"", ""Aligned Reads"": ""R_2014_01_14_16_21_42_user_MOL-95-Epilepsy70"", ""Library Type"": ""AmpliSeq""}}","{""FastqCreator"": {}}","{""coverageAnalysis"": {""Bases in target regions"": ""268545"", ""Amplicons with at least 1 read"": ""99.80%"", ""barcoded"": ""false"", ""Target base coverage at 100x"": ""97.72%"", ""Amplicons with at least 500 reads"": ""95.42%"", ""Total assigned amplicon reads"": ""4879939"", ""Reference (File)"": ""hg19"", ""Total aligned base reads"": ""884883559"", ""Target base coverage at 20x"": ""98.82%"", ""Number of amplicons"": ""1507"", ""Target bases with no strand bias"": ""84.70%"", ""Percent reads on target"": ""97.44%"", ""Amplicons with at least 100 reads"": ""98.08%"", ""Average base coverage depth"": ""3149"", ""Average reads per amplicon"": ""3238"", ""Using"": ""All Mapped Reads"", ""Amplicons reading end-to-end"": ""80.76%"", ""Non-duplicate"": """", ""Uniquely mapped"": ""No"", ""Targeted Regions"": ""Epilepsy70"", ""Uniformity of base coverage"": ""93.35%"", ""Targetted regions"": ""/results/uploads/BED/42/hg19/merged/plain/Epilepsy70.bed"", ""Target padding"": ""0"", ""Amplicons with at least 20 reads"": ""99.14%"", ""Number of mapped reads"": ""5007953"", ""Percent assigned amplicon reads"": ""97.44%"", ""Amplicons 
+2

'return'是唯一合法的shell函數不是一個腳本。 「線路」應該從哪裏讀取?引用變量時,你使用它們'echo「$ line yes」'。 –

+0

@EtanReisner,也許這個代碼實際上是在一個函數裏面,他只是發佈了一個示例代碼。雖然只是樂觀的假設。 – Jahid

+0

@Jahid我假設它不是以'#!/ bin/bash'開始的。 =) –

回答

1

更改while循環的內容:

while IFS= read -r line 
do 
case "$line" in 
    *$id*) 
     echo "$line" >> bashgrep.txt 
     echo "yes" 
#Assumed you want only $line to go to the file and print yes to stdout 
     ;; 
    *) 
     echo "no" 
     ;; 
esac 
done <download.txt 
#change it to the name of the file downloaded. 
#Your posted code seems to download getCSV.txt 
+0

它是問題中的'download.txt',但OP代碼示例中的'getCSV.txt'。這可能需要修復。 –

+0

@MichaelJaros,yap,目前還不清楚他是否以原始代碼下載爲download.txt或getCSV.txt。 – Jahid

+0

謝謝大家:),我正在學'bash'真的很贊它:) – Chris

相關問題