in reply to Can you help me with these one-liners?
Example1: perl -e 'while(<>) {if($_=~/^>/) {print $_;} else {$_=~tr/ATCG/TAGC/; +print $_;}}' FILE
Use -n to replace the while loop:
perl -nle 'if($_=~/^>/) {print $_;} else {$_=~tr/ATCG/TAGC/; print $_; +}' FILE
Do away with the unnecessary explicit references to $_:
perl -nle 'if(/^>/) {print;} else { tr/ATCG/TAGC/; print; }' FILE
Recognise that every line is being printed, so -p can replace the explicit print statements:
perl -ple 'if(/^>/) { ; } else { tr/ATCG/TAGC/; }' FILE
Rearrange to do away with the empty if body:
perl -ple 'tr/ATCG/TAGC/ unless( /^>/ );' FILE
UPDATE: a final step:
perl -ple '/^>/ or tr/ATCG/TAGC/' FILE
|
|---|