シェルスクリプトからファイルデータを抽出中にエラーが発生しました。

シェルスクリプトからファイルデータを抽出中にエラーが発生しました。

シェルスクリプトを作成しようとすると理解できないエラーが発生します。スクリプトは次のとおりです。

#!/bin/bash
while read id 
do 
cat demuxR1/$id.barcode.in.R1.R1.fastq demuxR2/$id.barcode.in.R2.R2.fastq > alldemulti/$id.forwardread.fastq 
done < R1_new.txt

demuxR1 および demuxR2 フォルダのファイルにはファイルが含まれています。ここに画像の説明を入力してください。名称は図のとおりです。出力はalldemultiという別のフォルダにリダイレクトする必要があります。スクリプトを実行すると文句を言います。

cat: demuxR1/SAE1903.barcode.in.R1.R1.fastq.barcode.in.R1.R1.fastq: No such file or directory

R1_new.txtファイル名を含める:

    SAE1903.barcode.in.R1.R1.fastq
    SAE1903.barcode.in.R1.R2.fastq
    SAE2000.barcode.in.R1.R1.fastq
    SAE2000.barcode.in.R1.R2.fastq
    SAE2103.barcode.in.R1.R1.fastq
    SAE2103.barcode.in.R1.R2.fastq
    SAE2203.barcode.in.R1.R1.fastq
    SAE2203.barcode.in.R1.R2.fastq
    SAE2303.barcode.in.R1.R1.fastq
    SAE2303.barcode.in.R1.R2.fastq
    SAE2403.barcode.in.R1.R1.fastq
    SAE2403.barcode.in.R1.R2.fastq
    SAE2603.barcode.in.R1.R1.fastq
    SAE2603.barcode.in.R1.R2.fastq
    SAE2803.barcode.in.R1.R1.fastq
    SAE2803.barcode.in.R1.R2.fastq

誰かが私がここで何を間違っているのか教えてもらえますか?

ディレクトリの内容demuxR1:

合計 4426752
-rwxrwxrwx 1 Molloy Molloy561 10月15日 08:46 Barcode_R1.txt
-rwxrwxrwx 1 molloy molloy231092 10月15日 09:14 SAE1903.barcode.in.R1.R1.fastq
-rwxrwxrwx 1 molloy molloy235734 10月15日 09:14 SAE1903.barcode.in.R1.R2.fastq
-rwxrwxrwx 1 Molloy Molloy917692 10月15日 09:14 SAE2000.barcode.in.R1.R1.fastq
-rwxrwxrwx 1 Molloy Molloy935522 10月15日 09:14 SAE2000.barcode.in.R1.R2.fastq
-rwxrwxrwx 1 Molloy Molloy1129320 10月15日 09:14 SAE2103.barcode.in.R1.R1.fastq
-rwxrwxrwx 1 Molloy Molloy1151554 10月15日 09:14 SAE2103.barcode.in.R1.R2.fastq
-rwxrwxrwx 1 molloy molloy747736 10月15日 09:14 SAE2203.barcode.in.R1.R1.fastq
-rwxrwxrwx 1 Molloy Molloy762462 10月15日 09:14 SAE2203.barcode.in.R1.R2.fastq
-rwxrwxrwx 1 molloy molloy446168 10月15日 09:14 SAE2303.barcode.in.R1.R1.fastq
-rwxrwxrwx 1 Molloy Molloy455044 10月15日 09:14 SAE2303.barcode.in.R1.R2.fastq
-rwxrwxrwx 1 Molloy Molloy378862 10月15日 09:14 SAE2403.barcode.in.R1.R1.fastq
-rwxrwxrwx 1 Molloy Molloy386440 10月15日 09:14 SAE2403.barcode.in.R1.R2.fastq
-rwxrwxrwx 1 Molloy Molloy960420 10月15日 09:14 SAE2603.barcode.in.R1.R1.fastq
-rwxrwxrwx 1 molloy molloy979364 10月15日 09:14 SAE2603.barcode.in.R1.R2.fastq
-rwxrwxrwx 1 Molloy Molloy1256116 10月15日 09:14 SAE2803.barcode.in.R1.R1.fastq
-rwxrwxrwx 1 Molloy Molloy1281112 10月15日 09:14 SAE2803.barcode.in.R1.R2.fastq
-rwxrwxrwx 1 moloy moloy 2258319418 10月15日 09:14 Unknown.R1.fastq
-rwxrwxrwx 1 moloy moloy 2257956950 10月15日 09:14 Unknown.R2.fastq

ディレクトリの内容demuxR2:

合計 4427776
-rwxrwxrwx 1 Molloy Molloy560 10月14日 12:48 Barcode_R2.txt
-rwxrwxrwx 1 Molloy Molloy261854 10月15日 10:11 SAE1903.barcode.in.R2.R1.fastq
-rwxrwxrwx 1 molloy molloy256718 10月15日 10:11 SAE1903.barcode.in.R2.R2.fastq
-rwxrwxrwx 1 Molloy Molloy1284362 10月15日 10:11 SAE2000.barcode.in.R2.R1.fastq
-rwxrwxrwx 1 Molloy Molloy1259358 10月15日 10:11 SAE2000.barcode.in.R2.R2.fastq
-rwxrwxrwx 1 Molloy Molloy1208280 10月15日 10:11 SAE2103.barcode.in.R2.R1.fastq
-rwxrwxrwx 1 molloy molloy1184716 10月15日 10:11 SAE2103.barcode.in.R2.R2.fastq
-rwxrwxrwx 1 Molloy Molloy1028542 10月15日 10:11 SAE2203.barcode.in.R2.R1.fastq
-rwxrwxrwx 1 Molloy Molloy1008462 10月15日 10:11 SAE2203.barcode.in.R2.R2.fastq
-rwxrwxrwx 1 molloy molloy627558 10月15日 10:11 SAE2303.barcode.in.R2.R1.fastq
-rwxrwxrwx 1 molloy molloy615364 10月15日 10:11 SAE2303.barcode.in.R2.R2.fastq
-rwxrwxrwx 1 molloy molloy414098 10月15日 10:11 SAE2403.barcode.in.R2.R1.fastq
-rwxrwxrwx 1 molloy molloy405878 10月15日 10:11 SAE2403.barcode.in.R2.R2.fastq
-rwxrwxrwx 1 Molloy Molloy1231900 10月15日 10:11 SAE2603.barcode.in.R2.R1.fastq
-rwxrwxrwx 1 Molloy Molloy1208060 10月15日 10:11 SAE2603.barcode.in.R2.R2.fastq
-rwxrwxrwx 1 Molloy Molloy1784282 10月15日 10:11 SAE2803.barcode.in.R2.R1.fastq
-rwxrwxrwx 1 Molloy Molloy1749406 10月15日 10:11 SAE2803.barcode.in.R2.R2.fastq
-rwxrwxrwx 1 moloy moloy 2256301114 10月15日 10:11 Unknown.R1.fastq
-rwxrwxrwx 1 moloy moloy 2256668336 10月15日 10:11 Unknown.R2.fastq

ベストアンサー1

入力ファイルには、実際には次のように1行に1つのファイル名しか含まれていないとします。

SAE1903.barcode.in.R1.R1.fastq
SAE1903.barcode.in.R1.R2.fastq
SAE2000.barcode.in.R1.R1.fastq
...

スクリプトは各行を読み取るため、id最初の行の後のid値はですSAE1903.barcode.in.R1.R1.fastq。この変数を使用すると、変数が値$id.barcode.in.R1.R1.fastqに置き換えられ、残りの.barcode.in.R1.R1.fastq文字列()が追加されます。もちろん、名前が何もないのでエラーが発生しますSAE1903.barcode.in.R1.R1.fastq.barcode.in.R1.R1.fastq

簡単な解決策(ファイルに偶数行があると仮定)でこの問題を克服できます。

#!/bin/bash
while read line1; do
    read line2
    cat "demuxR1/$line1" "demuxR2/$line2" > "alldemulti/${line1%%.*}.forwardread.fastq"
done < R1_new.txt

たとえば、ファイルから読み取られた文字列の最初の点の前の単語${line1%%.*}に置き換えられます。SAE1903

おすすめ記事