On Mar 16, 8:55 am, superdu (nobody@cares) wrote:
> Hi,
> Being a beginner in Linux I hit this problem which I know can be
> solved by scripting. I recovered a bunch of files from a disk crash
> that contains all my emails but they were in 2 mb chunks and in no
> particular demarkation. So i combined them into one huge file.
>
> To break them into smaller messages I need to search for a line say
> "---Next_Part ...blah bla ----
> an take everything between the two lines and create the new text
> file as 00000????.txt. Thats all that need to be done in order for
> me to read these email or resend them to myself. Sorry if I am
> missing the obvious but as I said my knowledge in scripting is very
> limited. Like upto shebang
These emails are urgent otherwise I
> would have spent some time to learn a bit more scripting.
>
> Any is much appreciated.
>
> Regards.
>
> superdu
> =============
> Just a noob
>
> --
> --------------------------------- --- -- -
> Posted with NewsLeecher v3.8 Final
> Web @http://www.newsleecher.com/?usenet
> ------------------- ----- ---- -- -
If the input file contains:
---Next_Part
line 1
line 2
---Next_Part
line 2.1
line 2.2
---Next_Part
Then the following Shell program:
#!/bin/sh
i=0
/bin/cat $1 |
while read r; do
if echo "$r" | /bin/grep "^---Next_Part" 2>&1 >/dev/null; then
[ -f /tmp/mail.$$ ] && /bin/mv /tmp/mail.$$ mail.$i
i=`/bin/expr $i + 1`
continue
fi
echo "$r" >>/tmp/mail.$$
done
Will create two files with the following names and contents:
# cat mail.1
line 1
line 2
# cat mail.2
line 2.1
line 2.2
#
Shawn Ayromloo