linux - awk error with "[" and "]" delimiters -
i have string looks likes this
string="xxxxx.yyyyy[2].zzzzz" i want extract number between [ ]. used next awk command
echo $string | awk -f'[]' '{print $2}' but awk command returns error:
awk: bad regex '[]': unmatched [ or [^ how prepare that?
this should work:
echo "xxxxx.yyyyy[2].zzzzz" | awk -f '[][]' '{print $2}' 2 order of ] before [ within character class of import here.
this shall work double escaping [ , ] using alternation regex:
echo "xxxxx.yyyyy[2].zzzzz" | awk -f '\\[|\\]' '{print $2}' 2 or:
echo "xxxxx.yyyyy[2].zzzzz" | awk -f '[\\[\\]]' '{print $2}' 2 linux shell awk ash
No comments:
Post a Comment