0
$\begingroup$

I am attempting to edit my fastq sequence files with an awk command from a published article. The sequence files are all contained in one directory where I am running the awk command from the terminal in a Linux environment. There are 4 fastq files in the directory

01_thu159_IX_RNA_001.fastq
01_thu163_IX_RNA_001.fastq
01_thu164_IX_RNA_001.fastq
01_thu190_IX_RNA_001.fastq

I would like to trim all these files at once with the awk command so I wrote this for loop:

for filename in ./*.fastq*
do
awk -v s=10 -v e= 40 ' {if (NR%2 == 0) print substr ($0, s+1, length ($0)-s-e); else print $0;} ' ./${filename} >  ./${filename}_trimmed
done

However, I am getting the following error:

awk: fatal: cannot open file ` {if (NR%2 == 0) print substr ($0, s+1, length ($0)-s-e); else print $0;} ' for reading (No such file or directory)

I then thought maybe it was an error with the for loop so I tried the command as per the instructions in the article

awk -v s=10 -v e= 40 '{if (NR%2 == 0) print substr ($0, s+1, length ($0)-s-e); else print $0;}' ./01_thu159_IX_RNA_001.fastq > ./Trim_01_thu159_IX_RNA_001.fastq

But this also produced the same error:

awk: fatal: cannot open file `{if (NR%2 == 0) print substr ($0, s+1, length ($0)-s-e); else print $0;}' for reading (No such file or directory)

I have checked the syntax for the awk command and it should be correct. Could anyone please give me advice as to what I am doing wrong and how to fix this issue?

$\endgroup$

1 Answer 1

3
$\begingroup$

You have a whitespace here:

e= 40

awk thinks that 40 is your rule and the rest of the line is a filename.

$\endgroup$
1
  • $\begingroup$ Thank you very much really appreciate it, I didn't notice that. Will give it a try now again. $\endgroup$
    – Justin1609
    Aug 22, 2021 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.