user1082013
user1082013

Reputation: 63

using grep to parse output from another command

after doing the command in the terminal: forever list

i get the following output:

info:   Forever processes running
data:       uid  command script           forever pid logfile                              uptime        
data:   [0] 0ClV node    enfomo-server.js 376     377 /Users/USERNAME/.forever/0ClV.log 0:0:37:26.987 

i need to use grep or some alternative to give as output the following string only:

/Users/USERNAME/.forever/0ClV.log

what is the proper command?

Upvotes: 2

Views: 6299

Answers (2)

Kai Sternad
Kai Sternad

Reputation: 22850

You can do this with grep using the -o flag which only prints the matching part:

forever list | grep -o '\/Users.*log'

Upvotes: 3

Paul Beckingham
Paul Beckingham

Reputation: 14925

First you might want to isolate only the lines you want with grep, then awk would work:

grep node file | awk '{print $7}'

or cut:

grep node file | cut -d\  -f7

Upvotes: 2

Related Questions