A string of greps inside double quotes

Trying to grep a string inside double quotes at the moment I'm using this

grep user file | grep -e "[\'\"]" 

This will lead to the section of the file I need and highlight double quotes, but it will not give the sting in double quotes

+6
source share
3 answers

Try to do this:

 $ cat aaaa foo"bar"base $ grep -oP '"\K[^"\047]+(?=["\047])' aaaa bar 

I use extended regex methods.

If you also want to use quotation marks:

 $ grep -Eo '["\047].*["\047]' "bar" 

Note:

 \047 

- octal representation of ascii single quote

+9
source
 $ cat aaaa foo"bar"base $ grep -o '"[^"]\+"' "bar" 
+6
source

Try:

 grep "Test" /tmp/junk | tr '"' ' ' 

This will remove the quotes from grep output

Or you can try the following:

 grep "Test" /tmp/junk | cut -d '"' -f 2 

This will use quotation marks as a delimiter. Just specify the field you want to select. This will allow you to select the necessary information.

+1
source

All Articles