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/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

for id in $(cut -f1 ids.txt); do
    cat FILE.fa | sed /$id/',/>/!d' | awk '/>/{i++}i==1'> $id.fa
Z. Lu avatar
Z. Lu
Data science, bioinfo, scripting, parasites, retro, plain text.
comments powered by Disqus