0

I've below text, how can I extract list

[83472, 8327489] and abcd: 32324 ?

[83472, 8327489]abcd: 32324Expr bla bla
[243fd]abcd: 4342Expr ieddsk
[2324, 34543, 8937423]abcd: 3232432423423Expr bla bla
0

2 Answers 2

2
sed -E 's/(\[[^]]*\]abcd:[[:blank:]]*[[:digit:]]*).*/\1/' file

should do it.

Sample Output

[83472, 8327489]abcd: 32324
[243fd]abcd: 4342
[2324, 34543, 8937423]abcd: 3232432423423
2
  • Why not just sed -E 's/Expr.*//' file ? Commented Sep 1, 2016 at 20:17
  • @DJMcMayhem That would not work in the rare cases like [Expr. 8327489] abcd: 32324Expr bla bla Commented Sep 1, 2016 at 20:23
0

With grep and pcre

1) to extract upto but not including Expr and rest of line

$ grep -oP '.*(?=Expr)' file
[83472, 8327489]abcd: 32324
[243fd]abcd: 4342
[2324, 34543, 8937423]abcd: 3232432423423

2) to extract [...]abcd: numbers

$ grep -oP '\[[^]]*\]abcd:\s*\d+' file
[83472, 8327489]abcd: 32324
[243fd]abcd: 4342
[2324, 34543, 8937423]abcd: 3232432423423

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.