I have the following linux cmd:
grep -o file.txt "\"uri\":\".{1,}\""
The text i have is the following:
"some characters here","uri":"some_URI*Here.^%$#!", "again a set of irrelevant characters"
Of course the output i want to have is:
"uri":"some_URI*Here.^%$#!"
Why dont i have the correct output? Because of the " required by the grep which mix with " in my text? How to fix it?
You could use the following regex:
grep -oE '"uri":".[^"]+"' inputFile
Original poster provided a regex that is almost correct but have some flaws, below is his/her version and a corrected one:
grep -o inputFile "\"uri\":".{1,}\"" # wrong
grep -oE '"uri":"[^"]{1,}"' inputFile # correct
The problems with the first use of grep are:
-E
flag for {1,}
to work[^"]
character class instead of .