Issue
How to remove the ### from grep output?
File containing:
### Invoked at: Wed Dec 7 22:24:35 2022 ###
My grep command:
grep -oP "Invoked at: \K(.*)" $file
Expected output:
Wed Dec 7 22:24:35 2022
Current output:
Wed Dec 7 22:24:35 2022 ###
Solution
Use this:
grep -oP "Invoked at: \K.*\d+" "$file"
(no need parenthesis).
The regular expression matches as follows:
Node | Explanation |
---|---|
Invoked at: |
'Invoked at: ' |
\K |
resets the start of the match (what is K ept) as a shorter alternative to using a look-behind assertion: look arounds and Support of K in regex |
.* |
any character except \n (0 or more times (matching the most amount possible)) |
\d+ |
digits (0-9) (1 or more times (matching the most amount possible)) |
Answered By - Gilles Quénot Answer Checked By - Gilberto Lyons (WPSolving Admin)