heyvOOn

Grep a string inside double quotes

Jun 18th, 2018 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.32 KB | None | 0 0
  1. How to grep a string inside double quotes using Perl syntax (-Po)
  2.  
  3. $ cat aaaa
  4. foo"bar"base
  5. $ grep -Po '"\K[^"\047]+(?=["\047])' aaaa
  6. bar
  7. I use look around advanced regex techniques.
  8.  
  9. If you want the quotes too :
  10.  
  11. $ grep -Eo '["\047].*["\047]'
  12. "bar"
  13. Note :
  14.  
  15. \047
  16. is the octal ascii representation of the single quote
Add Comment
Please, Sign In to add comment