chippycentra
chippycentra

Reputation: 879

sed an remove everything after the first pattern (only in the line)

let say i have a file such as

>Species_Name|KIOOL
AATATATATACACACAAGAGAGGA
>SPECIES_name|KUI
AATTAGAGAGA
>Species_names|POPPO
ATATGAATATA

How could I in bash get a new file such as :

>Species_Name
AATATATATACACACAAGAGAGGA
>SPECIES_name
AATTAGAGAGA
>Species_names
ATATGAATATA

I tried sed 's@|*@@'g my file but it does not work

Thank you

Upvotes: 1

Views: 312

Answers (1)

John1024
John1024

Reputation: 113994

|* matches zero or more vertical bars. You appear to want to match one vertical bar followed by zero or more alphanumeric characters. Try:

$ sed 's/|[[:alnum:]]*//' file
>Species_Name
AATATATATACACACAAGAGAGGA
>SPECIES_name
AATTAGAGAGA
>Species_names
ATATGAATATA

In the revised question, it appears that you might want to remove everything after the first vertical bar. In that case, replace [[:alnum:]] with . since . matches anything:

$ sed 's/|.*//' file
>Species_Name
AATATATATACACACAAGAGAGGA
>SPECIES_name
AATTAGAGAGA
>Species_names
ATATGAATATA

Upvotes: 3

Related Questions