There is a view script
awk '/before[az]+after/{print > ?? ".txt" }' filename
Instead ?? it is required to obtain the recognized value of the [az] + pattern, so that the file name equals this value.
How to achieve this?
There is a view script
awk '/before[az]+after/{print > ?? ".txt" }' filename
Instead ?? it is required to obtain the recognized value of the [az] + pattern, so that the file name equals this value.
How to achieve this?
Not this way?
awk '{if (match($0, /before([az]+)after/, a)) {print a[1]}}'
However, another encrypted question ...
...print > $1... [s@pandora6 20130303]$ cat qwert.txt beforeaaaaafter beforebbbaaaaafter beforeaacccaaafter beforeassssaaaafter [s@pandora6 20130303]$ awk '/before[az]+after/{print > $1 ".txt" }' qwert.txt [s@pandora6 20130303]$ ls -t1r beforebbbaaaaafter.txt beforeassssaaaafter.txt beforeaacccaaafter.txt beforeaaaaafter.txt
I do not know why you need it .. but it seems so))
Assuming that you can use standard backreferences in awk. Take [az] + in parentheses (you get a group) and you can get its content using the group number \ \ group number.
Total should make something like
awk '/before([az]+)after/{print > \1 ".txt" }' filename
Who cares, it turned out through gawk:
cat filename | gawk 'match($0, /before([az]+)after/, x) {print $0 > x[1] ".txt" }'
Source: https://ru.stackoverflow.com/questions/204354/
All Articles