Issue
Hi everyone!
I wrote a script that worked in the past, but suddenly it does not work and I have no idea why.
Here is my script:
#!/bin/bash
#This script gets damage seq bed files of 4 nucleotides and filters only those with dipyrimidins in 2-3 position.
_pwd=$PWD
#hg-19 ref genome.
genome_path="/hg_19_ref_genome.fa"
#Scans all the damage seq given bed files.
for bedFile in $_pwd/*.bed
do
#Removes duplicates lines.
sort -u -o $bedFile $bedFile
#Sorts the files according to chromosome and coordinates.
sort -k1,1 -k2,2n -o $bedFile $bedFile
name=`basename $bedFile`
#Adjusts the fasta file name.
faName="${name%.bed*}.fa"
bedtools getfasta -s -fi $genome_path -bed $bedFile -name -fo $_pwd/fasta_files/$faName #Gets the sequence itself.
done
#Scans all the obtained fasta files.
for faFile in $_pwd/fasta_files/*.fa
do
name=`basename $faFile`
faOutput="${name}"
bedOutput="${name%.fa*}.bed"
#Filters the files for getting only those which contain dypirimidne in 2-3 columns.
cat $faFile |\
paste - - |\
awk 'toupper(substr($2,2,2)) ~ /^(TT|TC|CT|CC)$/' |\
tr "\t" "\n" |\
tee $_pwd/filtered_fasta/$faOutput |\
awk -F '[>():-]' '/^>/ {printf("%s\t%s\t%s\t%s\t%s\t%s\n",$4,$5,$6,$2,$2,$7);}' > $_pwd/filtered_bed/$bedOutput
done
When I run it, I get this error:
line 30: : command not found
where line 30 is this line:
tee $_pwd/filtered_fasta/$faOutput |\
I have no idea why this error occurs, it worked fine before.
I really hope someone can help me with that issue.
UPDATE: I deleted all the '' and it works fine now.
Solution
If I should believe that you've pasted your script correctly, there is a character in line 30 after the backslash \
.
The Bash itself is telling you name of the unknown command:
line 30: : command not found
The thing between :
is name of command that Bash was unable to recognize and this thing is - a white space.
As suggested in comments, remove the backslashes \
after pipe |
and make sure that the pipe character is the last one in line. This will improve readability.
Also, good editor can show white spaces (example for Sublime Text). Enabling it will show you such mistakes.
Answered By - smbear Answer Checked By - Cary Denson (WPSolving Admin)