2017-03-14 58 views
0

我有一個問題如何將變量字符串傳遞給測試biginig中的文件txt?

我有一個程序一般是這樣gene.sh

,對於所有文件(ES文件:geneX.csv)使與基因的名稱(例如目錄:GENEX/GENEX .csv)接下來這個程序在gene.sh內編譯一個其他程序,但是這個程序需要一個varieble,我不知道它是如何做到的。

這是程序gene.sh

#!/bin/bash 

# Create a dictory for each file *.xls and *.csv 

for fname in *.xlsx *csv 
    do 
      dname=${fname%.*} 

      [[ -d $dname ]] || mkdir "$dname" 
      mv "$fname" "$dname" 
    done 

# For each gene go inside the directory and compile the programs getChromosomicPositions.sh to have the positions, and getHapolotipeStings.sh to have the variants 

for geni in */; do 
    cd $geni 
    z=$(tail -n 1 *.csv | tr ';' "\n" | wc -l) 
    cd .. 
    cp getChromosomicPositions.sh $geni ---> 
    cp getHaplotypeStrings.sh $geni 
    cd $geni 
    export z 
    ./getChromosomicPositions.sh *.csv 
    export z 
    ./getHaplotypeStrings.sh *.csv 
    cd .. 
done 

這是程序getChromosomichPositions.sh:

rm chrPosRs.txt 

grep '^Haplotype\ ID' $1 | cut -d ";" -f 4-61 | tr ";" "\n" | awk '{print "select chrom,chromStart,chromEnd,name from snp147 where name=\""$1"\";"}' > listOfQuery.txt 

while read l; do 

    echo $l > query.txt 
    mysql -h genome-mysql.cse.ucsc.edu -u genome -A -D hg38 --skip-column-names <query.txt> queryResult.txt 

    if [[ "$(cat queryResult.txt)" == "" ]]; 
    then  

     cat query.txt | 
     while read line; do 
       echo $line | awk '$6 ~/rs/ {print $6}' > temp.txt; 
       if [[ "$(cat temp.txt)" != "" ]]; 
         then cat temp.txt | awk -F'name="' '{print $2}' | sed -e 's/";//g' > temp.txt; 
      ./getHGSVposHG19.sh temp.txt ---> Hear the problem---> 
       else 
         echo $line | awk '{num=sub(/.*:g\./,"");num+=sub(/\".*/,"");if(num==2){print};num=""}' > temp2.txt 
       fi 
     done 
     cat query.txt >> varianti.txt 
     echo "Missing Data" >> chrPosRs.txt 
    else 
     cat queryResult.txt >> chrPosRs.txt 
    fi 

done < listOfQuery.txt 

rm query* 

聽到這個問題:

我需要在文件中臨時進入。 txt並自動在文件的開頭放置程序基因的變量$ geni.sh

我該怎麼做?

+0

例如在TEMP.TXT有: 35941G>甲 我通過變量$ GENI慣於(例如:GENI = 「CBA1」)更改文件TEMP.TXT中: CBA1:35941G>甲 –

+1

你不能編輯你的問題而不是評論它嗎?當你處理它時,你可以修改格式,特別是'!#/ bin/bash'行。 \ [編輯]你在我寫作的時候糾正了這條線。 –

回答

0

爲什麼不傳遞"$geni"作爲調用腳本時的第一個參數,並將其餘參數視爲預期的.csv文件。

./getChromosomicPositions.sh "$geni" *.csv

或者,你可以將其設置爲腳本環境變量,以便它可以在那裏使用(或只是將其導出)。

echo "${1}:$(cat temp.txt | awk -F'name="' '{print $2}' | sed -e 's/";//g')

,或者如果它被傳遞:

geni="$geni" ./getChromosomicPositions.sh *.csv

在任何情況下,一旦你擁有了它的第二個腳本可用,你可以,如果作爲第一個參數傳遞做

環境變量:

echo "${geni}:$(cat temp.txt | awk -F'name="' '{print $2}' | sed -e 's/";//g')

+0

我真的要你爲halp,但我tryed兩個命令,但在相同的情況下,他們不工作,我該怎麼辦 –

相關問題