shenwei356 / rush

A cross-platform command-line tool for executing jobs in parallel
https://github.com/shenwei356/rush
MIT License
846 stars 63 forks source link

Is it possible to escpae single quotes? #45

Closed apcamargo closed 1 year ago

apcamargo commented 1 year ago

I'm trying to use rush to parallelize this command that adds a suffix to FASTA headers, in order to remove possible duplications:

The command is as follows:

pigz -d -c MYCOCOSM_TRANSCRIPTOMES/Pooled_transcriptome.part_001.fna.gz | \
awk -v OFS="" '{if($0 ~ /^>/) {x[$0]++ ; print $0,"|",x[$0]} else print $0}' | \
seqkit seq -w 0 -u | pigz -3 > MYCOCOSM_TRANSCRIPTOMES_2/Pooled_transcriptome.part_001.fna.gz

Because of the ' in awk, this command won't work in rush. I can't replace it with double quotes either because I get the following error:

$ cat list.txt | rush -d 'pigz -d -c MYCOCOSM_TRANSCRIPTOMES/{} | awk "{if($0 ~ /^>/) {x[$0]++ ; print $0 "|" x[$0]} else print $0}"'

14:08:23.319 [ERRO] compile field delimiter: error parsing regexp: invalid nested repetition operator: `++`

Is there a way of escaping the single quotes? \' didn't work.

shenwei356 commented 1 year ago

I usually write like this, by escaping double quotes inside the awk expression.

$ echo 1 | awk '{print $_"_xx"}' 
1_xx

$ seq 3 | rush -k 'echo {} | awk "{print \$_\"_xx\"}" '
1_xx
2_xx
3_xx

The flag -q/--escape does not work well for complicated cases.

apcamargo commented 1 year ago

I'll try that. Thanks!