Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to do you invert search using grep perl?

I’ve been trying to get this but i don’t know how, I have been searching the internet but i cannot seem to find the solution for this, Any help would be appreciated,

My reference
How to invert result using grep?

gh pr view 6095 --repo freshGrad/main --json body | jq -r .body > temp.txt

#check file is not empty
if [ -s temp.txt ]; then
        # The file is not-empty.
        DESCRIPTION=$(grep -Po 'JCC-[0-9]{3,4}:\K.*' temp.txt) || echo "Something went wrong"
        echo "$DESCRIPTION"
        rm -f temp.txt
else
        # The file is empty.
        DESCRIPTION="No Description Provided"
        echo "$DESCRIPTION"
        rm -f temp.txt
fi

test number 1 JCC is not hyperlink
PR body string

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

JCC-452:Fix ServiceDate-OrderItem to correct drawdown order value calculation

output is good

Fix ServiceDate-OrderItem to correct drawdown order value calculation

test number 2 with hyperlink
Pr body string

[JCC-365]: Add new Variation Codes on Quote

[JCC-365]: https://myplace.atlassian.net/browse/JCC-365?atlOrigin=eyJpIjoi3NTljNzY6NjVmND23DlhMDU42fshYzA5YTRkg1LCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

Output

Something went wrong

Expected Output

Add new Variation Codes on Quote

>Solution :

Change you grep to this:

grep -m1 -Po 'JCC-\d{3,4}]?:\h*\K.*' temp.txt

In your script:

DESCRIPTION=$(grep -m1 -Po 'JCC-\d{3,4}]?:\h*\K.*' temp.txt) ||
echo "Something went wrong"

Note that JCC string has optional ] afterwards and you also need to use -m1 to grab only first match. \h* is also good to use to disallow leading spaces in output.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading