В одну сторону с sed
:
Содержимое script.sed
:
## Subbtitute line that matches the format with both numbers.
s/^\([0-9]\+\) [xyz]\{3\} \([0-9]\+\)$/\1 \2/
## If substitution succeed, go to label 'a'.
ta
## If substitution failed, go to label 'b'.
bb
## Save content to 'hold space'.
:a
H
## In last line, get content from 'hold space', remove numbers
## not needed in output and print.
:b
$ {
g
s/^\n//
s/\n[0-9]\+//g
p
}
Содержимое infile
:
text
33 xxx 7
more text
33 zzz 3
55 n
33 yyy 5
66 asf sdf
Запустите скрипт:
sed -nf script.sed infile
И вывод:
33 7 3 5