I'm using a shell script to read in a file and then piping the output to grep and trying to extract the string contained between two quotes (while excluding the quotes).
./readFile.sh | grep -e "[\^\"]*[\?\"]"
This returns the entire contents of the file I that I'm reading.
My file is organized this way:
TITLE="foo"
DATA="bar"
SERVER="foo.bar.server"
I read the regex tutorial here http://www.regular-expressions.info/lookaround.html and tried to use the lookahead and lookbehind as best as I could, but I don't understand what's wrong here.
check this example with grep with look-behind
kent$ echo 'TITLE="foo"
DATA="bar"
SERVER="foo.bar.server"'|grep -Po '(?<=")[^"]*'
foo
bar
foo.bar.server
alternative is grep -Po '"\K[^"]*'
If you want to give awk a chance it is pretty simple:
awk -F '"' 'NF>2{print $2}' inFile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With