awk - MAWK: Store match() in variable -
i try use mawk match() built-in function doesn't have third value variable:
match($1, /9f7fde/) { substr($1, rstart, rlength); } see doc.
how can store output variable named var when later want construct output this?
edit2 - complete example:
input file structure:
<iframe src="https://vimeo.com/191081157" frameborder="0" height="481" width="608" scrolling="no"></iframe>|random title|uploader|fun|tag1,tag2,tag3 <iframe src="https://vimeo.com/212192268" frameborder="0" height="481" width="608" scrolling="no"></iframe>|random title|uploader|fun|tag1,tag2,tag3 parser.awk:
{ embed = $1; title = $2; user = $3; categories = $4; tags = $5; } begin { fs="|"; } # regexp without pattern matching testing purposes match(embed, /191081157/) { id = substr(embed, rstart, rlength); } { print id"\t"title"\t"user"\t"categories"\t"tags; } expected output:
191081157|random title|uploader|fun|tag1,tag2,tag3 i want call id variable outside match() function.
mawk version:
mawk 1.3.4 20160930 copyright 2008-2015,2016, thomas e. dickey copyright 1991-1996,2014, michael d. brennan random-funcs: srandom/random regex-funcs: internal compiled limits: sprintf buffer 8192 maximum-integer 2147483647
the obvious answer seem be
match($1, /9f7fde/) { var = "9f7fde"; } but more general be:
match($1, /9f7fde/) { var = substr($1, rstart, rlength); }
Comments
Post a Comment