Isolate text with sed or similar utility

All,

I'm getting a list like the following and I'd like to kill each PID in turn.

        pid (17797)
        pid (21748)
        pid (21754)
        pid (21704)
        pid (2199)
        pid (2159)
        pid (17809)
        pid (21769)
        pid (21778)
        pid (21715)
        pid (2211)
        pid (2171)

How can I isolate the PID in ksh with sed or other utility?
Thank you!

No idea yourself?

Managed to extract numbers with sed using following command:

sed "s/[^0-9]//g"

---------- Post updated at 04:43 AM ---------- Previous update was at 04:42 AM ----------

What if I wanted to extract everything in between parentheses ( ) regardless of what's in there (letters, numbers, symbols, etc)?

1 Like

Hello ejianu,

Following may help you in same.

awk -F"[)(]" '{print $2}' Input_file
OR
sed 's/.*(//;s/).*//;'  Input_file

Output will be as follows.

17797
21748
21754
21704
2199
2159
17809
21769
21778
21715
2211
2171
 

EDIT: Adding one more solution with shell for same.

while read line
do
   line=${line##*(};
   echo ${line%%)*};
done < Input_file

Thanks,
R. Singh