Working Man Working Man - 29 days ago 12
Linux Question

Extracting numbers surrounded by parenthesis with grep

What should I write to find sublines like this

(3894569)
?

I have tried
\\([0-9]*\\)


but it ,for example in line

wiluefh/u3:2(920)


finds
3
and
2
and
920


I want only
920
so what I must improve?

My task was to print PID of process and subprocess using
awk
and
pstree
.

I have tried this

ps -aux | grep $1 | awk '( system("pstree -p " $2) )' | grep -oh "\ ([0-9]*\\)" > $2


$1
is PID of process

$2
is file name

Answer

You use character escaping twice. Delete / or ".

For example:

grep -oh "([0-9]*)" 

grep -oh \([0-9]*\)
Comments