This is my first chance to welcome a first timer, so ... WELCOME
I'm no awk junkie, but what the heck... I tried by creating a sample master file (with incomplete records, empty posts thrown in for good measure)
Code:
[/home/soumen/tmp] $ cat post.txt
12349 234 askasd
12-3kasdweqj
From : a@b.com
asdfasfasf
sadfasfas
asdfasf
asdfasf
From : c@d.com
xsdfxsfxsf
sxdfxsfxs
xsdfxsf
xsdfxsf
From : e@f.com
From : g@h.com
The awk script is :
Code:
[/home/soumen/tmp] $ cat psplit.sh
#!/bin/bash
awk 'BEGIN {i=0; system("rm post?.txt") }
{ if (/^From/) {
++i
} else {
fname="post"i".txt"
print $0 >> fname
close(fname)
}}' post.txt
[/home/soumen/tmp] $
Output:
Code:
[/home/soumen/tmp] $ ./psplit.sh
[/home/soumen/tmp] $ for i in post?.txt ; do echo "--------$i--------"; cat $i; done
--------post0.txt--------
12349 234 askasd
12-3kasdweqj
--------post1.txt--------
asdfasfasf
sadfasfas
asdfasf
asdfasf
--------post2.txt--------
xsdfxsfxsf
sxdfxsfxs
xsdfxsf
xsdfxsf
[/home/soumen/tmp] $
I'm sure the awk gurus would have a more elegant awk script
HTH