输入.txt:
d1
a4
TEXT|VALUE1
TEXT|VALUE2
.
c8
TEXT|NVALUE1
.
a10
TEXT|VALUE3
.
a13
TEXT|VALUE4
.
c15
TEXT|NVALUE2
.
d20
d23
.
对于 file1,搜索以分隔符 dot 开头a[number]*
并在分隔符 dot 处停止的字符串.
。
对于 file2,字符串以c[number]*
分隔符点开始并以点结束.
。
预期产出:
==> file1 <==
TEXT|VALUE1
TEXT|VALUE2
TEXT|VALUE3
TEXT|VALUE4
==> file2 <==
TEXT|NVALUE1
TEXT|NVALUE2
答案1
就像是:
awk '
$0 == "." { of = ""; next }
$0 ~ /^a[0-9]+$/ { of = "file1"; next }
$0 ~ /^c[0-9]+$/ { of = "file2"; next }
of != "" { print >of }
' input.txt