Error is listed below:
merge_star.sh: line 19: syntax error near unexpected token `('
merge_star.sh: line 19: `cat <(cat ~/asn_project/alignment_sorted/tmp/header.txt | sed 's/ /\t/g') ~/asn_project/alignment_sorted/tmp/tmp.out > ~/asn_project/alignment_sorted/STAR_counts.txt'
Line in .sh script in question:
cat <(cat ~/asn_project/alignment_sorted/tmp/header.txt | sed 's/ /\t/g') ~/asn_project/alignment_sorted/tmp/tmp.out > ~/asn_project/alignment_sorted/STAR_counts.txt
#!/bin/bash
# create header file
echo gene_name $(cd ~/asn_project/alignment_sorted && ls *_ReadsPerGene.out.tab | sed s/_ReadsPerGene.out.tab// | sort -u) > ~/asn_project/alignment_sorted/tmp/header.txt
Place each sample's STAR gene count file - ReadsPerGene.out.tab in the tmp/ directory
The 2nd column (-f2) of ReadsPerGene.out.tab contains the non-stranded counts
for sample in $(cd ~/asn_project/alignment_sorted && ls *_ReadsPerGene.out.tab | sed s/_ReadsPerGene.out.tab// | sort -u)
do
echo ${sample}
cat ~/asn_project/alignment_sorted/${sample}_ReadsPerGene.out.tab | tail -n +5 | cut -f2 > ~/asn_project/alignment_sorted/tmp/${sample}.count
done
get a list of gene ids (-f1)
tail -n +5 ~/asn_project/alignment_sorted/N_1_ReadsPerGene.out.tab | cut -f1 > ~/asn_project/alignment_sorted/tmp/geneids.txt
combine all the columns of the count files
paste ~/asn_project/alignment_sorted/tmp/geneids.txt ~/asn_project/alignment_sorted/tmp/*.count > ~/asn_project/alignment_sorted/tmp/tmp.out
add the header
cat <(cat ~/asn_project/alignment_sorted/tmp/header.txt | sed 's/ /\t/g') ~/asn_project/alignment_sorted/tmp/tmp.out > ~/asn_project/alignment_sorted/STAR_counts.txt
remove the tmp folder
rm -rf ~/asn_project/alignment_sorted/tmp
I am quite new to .sh script coding and I do not see what the error is telling me to fix. Any help is appreciated.
shellcheck.net
(online or download). It it quite usual for an earlier line to have an error that only manifests itself later. – Paul_Pedant Apr 23 '21 at 20:23sh merge_star.sh
in my school's HPC. – Tommy Nguyen Apr 23 '21 at 20:37cat <(cat ~/asn_project/alignment_sorted/tmp/header.txt | sed 's/ /\t/g')
correct, or did the site remove a '$' between the '<' and the '('? If the '$' is missing in the script itself, that might be your problem or part of it... – C. M. Apr 23 '21 at 21:33<( .. )
is process substitution, it makes the output of the command inside available as if in a file. Ifheader.txt
contains some sort of a header, it would print that (after passing throughsed).
< $( ..)` would use the output of the command inside as a filename to read – ilkkachu Apr 23 '21 at 21:42