Pages

Friday, December 29, 2023

Lookbehind syntax to ignore quotes

Lookbehind syntax to ignore quotes


-t -w -g london -s 'yesterday' -e 'yesterday' -f 100000"

-t -w -g london -s "yesterday" -e 'yesterday' -f 100000"
-t -w -g london -s yesterday -e yesterday -f 100000"
Task is to extract the word after "-s" 
Command : grep -oP "(?<=-s \"|-s '|-s )[^'\" ]*"
Explanation

(?<=          : is the syntax for lookbehind

s \"|-s '|-s  : or condition to search the word after -s
[^'\" ]        : 
Output
yesterday
yesterday
yesterday

Command 2 : grep -oP -- '-s\s*\K([^ ]+)' file | tr -d \'\"