awk -F"[01]" '{}' 這種形式指定的分隔符是或的關系,即0或1作為分隔符;
awk -F"[0][1]" '{}' 這種形式指定的分隔符是合並的關系,即以“01”作為一個字符為分隔符。
故假如有test.txt文本文件只有一行:
1. mail from: tomcat@gmail.com 2. subject:hello 3. data:2012-07-12 17:00 4. content:Hello, The world. 5. 6. mail from: jerry@gmail.com 7. subject:congregation 8. data:2012-07-12 08:31 9. content:Congregation to you. 10. 11. mail from: jacob@gmail.com 12. subject:Test 13. data:2012-07-12 10:20 14. content:This is a test mail.
用命令:awk 'BEGIN {FS="[0-9]+[.]";OFS="\n"}{for(i=1;i<=NF;i++) printf("%d %s\n",i,$i)}' test.txt即可輸出如下格式的形式的文件:
1
2 mail from: tomcat@gmail.com
3 subject:hello
4 data:2012-07-12 17:00
5 content:Hello, The world.
6
7 mail from: jerry@gmail.com
8 subject:congregation
9 data:2012-07-12 08:31
10 content:Congregation to you.
11
12 mail from: jacob@gmail.com
13 subject:Test
14 data:2012-07-12 10:20
15 content:This is a test mail.