Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove part of the string from beginning of the line up to certain character [closed]

Tags:

bash

sed

awk

I have a file with 10000 lines like this:

Peptidyl-prolyl cis-trans isomerase A OS=Homo sapiens GN=PPIA PE=1 SV=2 - [PPIA] 0.8622399654 3.2730004556

I cant figure out how to remove part of the string up to square bracket, so that final output looks like this:

[PPIA] 0.8622399654 3.2730004556

So far I tried python re.sub, but can't match it to the beginning of the line.

like image 646
Bio21 Avatar asked Nov 30 '22 15:11

Bio21


2 Answers

With sed it's a simple substitution:

sed 's/^[^[]*\[/[/' input

^ means start of pattern space ("line"), and [^[] matches everything but [. * is a quantifier which means zero or more times. \[ is a literal [.

like image 194
Andreas Louv Avatar answered Dec 04 '22 04:12

Andreas Louv


With sed:

sed 's/^[^[]*//' file

Disadvantage: If a line doesn't contain [, sed outputs an empty line.

like image 20
Cyrus Avatar answered Dec 04 '22 04:12

Cyrus