Issue
I have the following text in a file, for example, output.txt
[test.tracking_utils] INFO: Tracking subtool usage: main_test
[TEST & SPEC] INFO: Uploaded file test.zip with bucket URI test/20210804144418.zip.
How to use grep o something similar to get the value as test/20210804144418.zip
?
I tried
tail output.txt | grep ". test/" | awk {print $NF}
tail output.txt | grep -m1 .test/ | rev | cut -d' ' -f1 | rev
it returns test/20210804144418.zip.
with extra .
do you know how to remove the extra .
at the end? any suggestion?
Solution
You may use this grep
:
grep -oE -m1 'test/[^[:blank:]]+\.[^.]+' file
test/20210804144418.zip
RegEx Details:
test/
: Matchtest/
[^[:blank:]]+
: Match 1+ of non-whitespace characters\.
: Match a dot[^.]+
: Match 1+ of any non-dot characters
Answered By - anubhava Answer Checked By - Willingham (WPSolving Volunteer)