What does ‘\K’ mean in this regex?

Since not all regex flavors support lookbehind, Perl introduced the \K. In general when you have: a\Kb When “b” is matched, \K tells the engine to pretend that the match attempt started at this position. In your example, you want to pretend that the match attempt started at what appears after the “access_token”:” text. This … Read more

Piping tail output though grep twice

I believe the problem here is that the first grep is buffering the output which means the second grep won’t see it until the buffer is flushed. Try adding the –line-buffered option on your first grep: tail -f access_log | grep –line-buffered “” | grep -v “.css” For more info, see “BashFAQ/009 — What is … Read more

Using grep to get the next WORD after a match in each line

Assuming you have gnu grep, you can use perl-style regex to do a positive lookbehind: grep -oP ‘(?<=GET\s/)\w+’ file If you don’t have gnu grep, then I’d advise just using sed: sed -n ‘/^.*GET[[:space:]]\{1,\}\/\([-_[:alnum:]]\{1,\}\).*$/s//\1/p’ file If you happen to have gnu sed, that can be greatly simplified: sed -n ‘/^.*GET\s\+\/\(\w\+\).*$/s//\1/p’ file The bottom line here … Read more