Issue
How to use grep
The string "[TEST-4902]: This is a long placeholder string"
command
gh pr view 1 --repo joe/test-gh-cli --json body --jq .body | grep -v "TEST-[0-9]{3,4}"
Result
[TEST-4902]: This is a long placeholder string
how to return only "This is a long placeholder string"
expected output
This is a long placeholder string
Solution
You are using extended functionality ERE
in a BRE
grep
so there is no match hence, your original line is returned.
If the -E
flag is added in conjunction with your -v
flag, then nothing will be printed as the match is now made so the line is ignored (not the part that is matched).
Using grep
with perl
style regex will do what you are looking for;
$ grep -Po 'TEST-[0-9]{3,4}]: \K.*' input_file
This is a long placeholder string
Answered By - HatLess Answer Checked By - Marie Seifert (WPSolving Admin)