Need to grep a specific string using curl
With awk
's match
function one could try following too.
your_curl_command | awk 'match($0,/^<html.*lang="[^"]*/){ val=substr($0,RSTART,RLENGTH) sub(/.*lang="/,"",val) print val}'
Explanation: Adding detailed explanation for above.
your_curl_command | awk ' ##Starting awk program from here.match($0,/^<html.*lang="[^"]*/){ ##using match function to match regex starting from <html till lang=" till next 1st occurrence of " val=substr($0,RSTART,RLENGTH) ##Creating val which has substring of matched values. sub(/.*lang="/,"",val) ##Substituting everything till lang=" with NULL in val here. print val ##printing val here.}'