sed tricks: conditional replacement


I wanted to change the read names in a fasta file. Basically, I wanted to run a sed replacement, but only on lines that start with >, changing lines like >GoodInfo_LotsOfTrash into just >GoodInfo, but I wanted to leave lines that didn’t start with > alone.

I found a nice answer:

<code>sed '/conditional_pattern/ s/pattern/replacement/g'

In my case, I wanted to chuck everything after an underscore _, so sed '/^>/ /_.*//'. The command line wins again.