
a.txt 内容如下 #this is 0 context abc ddd #this is 1 context xxx xxxx xxxxx #this is 2 context 1213
上面的 a.txt ,我想变成三个文件,靠#分割,变成 a_0.txt abc ddd
a_1.txt xxx xxxx xxxxx
a_2.txt 1213
1 hailongs OP 我去。。。 #this is 0 context abc ddd #this is 1 context xxx xxxx xxxxx #this is 2 context 1213 |
2 hailongs OP a_0.txt abc ddd a_1.txt xxx xxxx xxxxx a_2.txt 1213 |
3 cute 2016-12-19 13:48:55 +08:00 sed 's/ #/\n/g' a.txt |
5 slixurd 2016-12-19 14:09:42 +08:00 用 AWK 吧= = awk '{if( $0~/^#/) x++ ;else print > "txt"x}' file |
7 tftk 2016-12-19 14:31:40 +08:00 echo $a | tr '#' '\n' | while read line;do echo $line > youfile.txt;done |