Reputation: 5129
How can I combine this two expressions into one to be used in an awk script file?
awk '/select name="op_sys"/,/select>/' build/input.xhtml > build/output.xhtml
awk '/value="/,/">/' build/output.xhtml
Edit: I would like to transform the expressions in an awk file to look like:
#!/usr/bin/awk -f
{
...
}
Upvotes: 0
Views: 71
Reputation: 212404
awk
does not permit address ranges to be nested easily. You can do it with flags, but it's much simpler to use sed
:
sed -n '/pat1/,/pat2/ { /pat3/,/pat4/p }'
will print lines between pat3
and pat4
(inclusive) only within pat1
and pat2
. Note that nesting ranges like this does not behave exactly as piping the output to a second invocation, since overlaps will be treated differently.
Upvotes: 1
Reputation: 54502
I think it would be dangerous merging the two range expressions. For example, what if the second range occurs outside of (or partially overlaps) the first range? I would simply use a pipe:
< build/input.xhtml awk '/select name="op_sys"/,/select>/' | awk '/value="/,/">/'
Upvotes: 1