Answers.Body: <p>You have a whitespace here:</p>
  <pre><code>e= 40
  </code></pre>
  <p>awk thinks that 40 is your rule and the rest of the line is a filename.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-22T09:43:09.003Z
Answers.Text: Thank you very much really appreciate it, I didn't notice that. Will give it a try now again.
Answers.UserDisplayName: Justin1609
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-21T15:36:49.883Z
Answers.LastActivityDate: 2021-08-21T15:36:49.883Z
Answers.UserDisplayName: Arkadiusz Drabczyk
Body: <p>I am attempting to edit my <code>fastq</code> sequence files with an <code>awk</code> command from a published article. The sequence files are all contained in one directory where I am running the <code>awk</code> command from the terminal in a Linux environment. There are 4 fastq files in the directory</p>
  <pre><code>01_thu159_IX_RNA_001.fastq
  01_thu163_IX_RNA_001.fastq
  01_thu164_IX_RNA_001.fastq
  01_thu190_IX_RNA_001.fastq
  </code></pre>
  <p>I would like to trim all these files at once with the <code>awk</code> command so I wrote this <code>for</code> loop:</p>
  <pre><code>for filename in ./*.fastq*
  do
  awk -v s=10 -v e= 40 ' {if (NR%2 == 0) print substr (<span class="math-container">$0, s+1, length ($</span>0)-s-e); else print <span class="math-container">$0;} ' ./$</span>{filename} &gt;  ./${filename}_trimmed
  done
  </code></pre>
  <p>However, I am getting the following error:</p>
  <pre><code>awk: fatal: cannot open file ` {if (NR%2 == 0) print substr (<span class="math-container">$0, s+1, length ($</span>0)-s-e); else print $0;} ' for reading (No such file or directory)
  </code></pre>
  <p>I then thought maybe it was an error with the <code>for</code> loop so I tried the command as per the instructions in the article</p>
  <pre><code>awk -v s=10 -v e= 40 '{if (NR%2 == 0) print substr (<span class="math-container">$0, s+1, length ($</span>0)-s-e); else print $0;}' ./01_thu159_IX_RNA_001.fastq &gt; ./Trim_01_thu159_IX_RNA_001.fastq
  </code></pre>
  <p>But this also produced the same error:</p>
  <pre><code>awk: fatal: cannot open file `{if (NR%2 == 0) print substr (<span class="math-container">$0, s+1, length ($</span>0)-s-e); else print $0;}' for reading (No such file or directory)
  </code></pre>
  <p>I have checked the syntax for the <code>awk</code> 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?</p>
  
Tags: <rna-seq><fastq><linux><awk><read-correction>
Title: Error when using awk command to trim sequence files
ThreadText: # Error when using awk command to trim sequence files
  
  (Asked by: username_0 on 2021-08-21)
  
  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?
  
  **Tags:** rna-seq, fastq, linux, awk, read-correction
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-08-21. Score: 3
  
  You have a whitespace here:
  
  ```
  e= 40
  
  ```
  
  awk thinks that 40 is your rule and the rest of the line is a filename.
  
  > **Comments:**
  > **username_0**: Thank you very much really appreciate it, I didn't notice that. Will give it a try now again.  
  
  ---
  
  