kev*_*kev 73
如果你有 mail.txt
$ cat mail.txt
<html>
mail A
</html>
<html>
mail B
</html>
<html>
mail C
</html>
Run Code Online (Sandbox Code Playgroud)
跑去csplit
分手<html>
$ csplit mail.txt '/^<html>$/' '{*}'
- mail.txt => input file
- /^<html>$/ => pattern match every `<html>` line
- {*} => repeat the previous pattern as many times as possible
Run Code Online (Sandbox Code Playgroud)
检查输出
$ ls
mail.txt xx00 xx01 xx02 xx03
Run Code Online (Sandbox Code Playgroud)
如果你想要的话 awk
$ awk '/<html>/{filename=NR".txt"}; {print >filename}' mail.txt
$ ls
1.txt 5.txt 9.txt mail.txt
Run Code Online (Sandbox Code Playgroud)