Parse string with bash and extract number Parse string with bash and extract number unix unix

Parse string with bash and extract number


sed 's/.*pid \([0-9]*\).*/\1/'


Using AWK alone:

awk -F'[ ,]+' '{print $4}' inputfile


Solution with awk and cut

vinko@parrot:~$ cat testfrontend                         RUNNING    pid 16652, uptime 2:11:17nginx                            RUNNING    pid 16651, uptime 2:11:17redis                            RUNNING    pid 16607, uptime 2:11:32vinko@parrot:~$ awk '{print $4}' test | cut -d, -f 1166521665116607

for nginx only:

vinko@parrot:~$ grep nginx test | awk '{print $4}' | cut -d, -f 116651