Search code examples
bashgrepcut

How to grep and cut at the same time


Having trouble with grepping and cutting at the same time I have a file test.txt. Inside the file is this syntax

File: blah.txt Location: /home/john/Documents/play/blah.txt
File: testing.txt Location /home/john

My command is ./delete -r (filename), say filename is blah.txt.

How would i search test.txt for blah.txt and cut the /home/john/Documents/play/blah.txt out and put it in a variable


Solution

  • grep -P "^File: blah\.txt Location: .+" test.txt | cut -d: -f3