Naresh DJ
Naresh DJ

Reputation: 91

How to extract a string following a pattern using unix(mac OSX)

I have file with these columns and tab separated.

Jun-AP1(bZIP)/K562-cJun-ChIP-Seq(GSE31477)/Homer    12.88%  4926.5  9.08%
Maz(Zf)/HepG2-Maz-ChIP-Seq(GSE31477)/Homer  52.08%  25510.3 47.00%
Bach2(bZIP)/OCILy7-Bach2-ChIP-Seq(GSE44420)/Homer   10.81%  4377    8.06%
Atf3(bZIP)/GBM-ATF3-ChIP-Seq(GSE33912)/Homer    28.73%  13346.9 24.59%
TEAD4(TEA)/Tropoblast-Tead4-ChIP-Seq(GSE37350)/Homer    40.43%  19549.3 36.01%

In first column, I want to extract the string upto first bracket and keep rest of the columns same. For instance, I need the output as shown below.

Jun-AP1 12.88%  4926.5  9.08%
Maz 52.08%  25510.3 47.00%
Bach2   10.81%  4377    8.06%
Atf3    28.73%  13346.9 24.59%
TEAD4   40.43%  19549.3 36.01%

Thank you.

Upvotes: 0

Views: 227

Answers (2)

Claes Wikner
Claes Wikner

Reputation: 1517

awk '{sub(/\(.*Homer/,"")}{print $1,$2,$3,$4}' file

Jun-AP1 12.88% 4926.5 9.08%
Maz 52.08% 25510.3 47.00%
Bach2 10.81% 4377 8.06%
Atf3 28.73% 13346.9 24.59%
TEAD4 40.43% 19549.3 36.01%

Upvotes: 0

Steve Summit
Steve Summit

Reputation: 47933

I would start with

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

where that's an actual tab character in [^ ].

Upvotes: 1

Related Questions