Issue
I would like to extract string after x_rundir
from a file full with text.
Trying with
grep -w "x_rundir" xfile.txt
but it extracts whole sentence from the file
xfile.txt:
00:39:11-INFO: x_rundir: /i/am/a/path/
Expected result:
/i/am/a/path
Solution
You may use this gnu-grep command:
grep -oP 'x_rundir: \K\S+' xfile.txt
/i/am/a/path/
Here:
-P
enabled Perl regex mode-o
prints only matched text\K
resets matched info\S+
matches 1+ non-whitespaces
Answered By - anubhava Answer Checked By - Pedro (WPSolving Volunteer)