[BASH Scripting] code snippets for common bash commands
for R1 in *_R1_001.fastq.gz; do
sample=`basename $R1 _R1_001.fastq.gz`;
R2=${sample}_R2_001.fastq.gz;
subj=$(echo ${sample:0:5} | sed 's/_//g');
dir=$(pwd);
echo $subj ${dir}/$R1 ${dir}/$R2 >> ../fastq_list.txt;
done
#Print substring of a column
cat FILE | awk ' { print $1, $2 = substr($2, 1, 15), $3, $4, $5, $6 }'
paste -d' ' <(awk -F':' '{ print $1 }' SCZ.CLOZUK_rsFiltered.txt) <(awk '{ print $2,$3,$4,$5,$6,$7,$8,$9 }' SCZ.CLOZUK_rsFiltered.txt) > out.txt
# subselects file by columns which match pattern
for i in {1..22}; do
echo $i
FILE=PsychEncode_CNS.${i}.annot
pattern="gene"
awk -vp="$pattern" 'NR==1{for(i=1; i<=NF; i++) if ($i~p) {a[i]++;} } { for (i in a) printf "%s\t", $i; printf "\n"}' $FILE > geneMods/geneMods_PEC.${i}.annot
done
for i in {1..22}; do
echo $i
paste -d' ' <(awk ' { print $1, $2, $3, $4 }' CNS.${i}.annot) geneMods/geneMods_PEC.${i}.annot > geneMods/geneMods_PEC.${i}.annot.final
done
#courtesy: Sep
add_col="$SAMPLE $TPM"
## use process substitution to paste new column into file
paste datSalmon.csv <(echo $add_col | tr " " "\n") > temp.csv ## 1 value per line
#Add 'chr' to VCF file if necessary
awk '{if($0 !~ /^#/) print "chr"$0; else print $0}' all-panctx-merged.vcf > all-panctx-merged_chr.vcf