Featured image of post Shell sed commands

Shell sed commands

Sed for searching and replacing.

Search content between 2 words (seems to give the longest match):

sed -n "/START-WORD-HERE/,/END-WORD-HERE/p" input > output
sed '/correctly/, /locus_tag="Smp_/!d'

Replace string (support regexp)

sed 's/_1$//'
sed 's/_1\t/\t/'

Remove ending numbers on the first column

sed -E 's/^(.*)_[0-9]*\t/\1\t/' #neuron-12	EWB00-006016 --> neuron	EWB00-006016 

Remove/replace a string until the end of line

cat aug_ratt_combined_C1.gff | sed 's/;gene_name=.*// | less'

Get the sequences from a fasta file

1
2
3
for id in $(cut -f1 ids.txt); do
    cat FILE.fa | sed /$id/',/>/!d' | awk '/>/{i++}i==1'> $id.fa
done
comments powered by Disqus
CC-BY-NC 4.0
Built with Hugo Theme Stack