Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to grep and cut at the same time

Tags:

grep

bash

cut

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

like image 220
Johnathon Avatar asked Dec 12 '22 12:12

Johnathon


1 Answers

grep -P "^File: blah\.txt Location: .+" test.txt | cut -d: -f3
like image 100
Blagovest Buyukliev Avatar answered Dec 28 '22 22:12

Blagovest Buyukliev