bash根据用户输入搜索文件并创建新文件



在下面的bash中,打开程序时会下载一个文件,然后根据用户输入搜索该文件,并将结果写入新文件。 截至目前,文件已下载并提示用户输入,但在输入后没有任何反应。

例如,打开bash并下载下载.txt,然后用户输入 id (NA04520)。id 用于搜索下载.txt行用于匹配.txt。代码运行,但没有输出结果。最终,我将在找到 id 的行中搜索特定文本,但我认为根据用户输入进行搜索是一个好的开始。谢谢:)。

#!/bin/bash
cd 'C:UserscmccabeDesktopwget'
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv --progress=bar:force 2>&1 | tail -f -n +6 
{
printf "nn"
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

下载内容.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 

将 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

相关内容

  • 没有找到相关文章

最新更新