|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 Iwould 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 ------------------- ----- ---- -- - |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
In comp.unix.shell nobody@cares <superdu>:
> 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. No backup and using doze? > 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 awk 'BEGIN{RS="---Next_Part"}{print $0 > "mail"NR}' infile Something in the lines should do the trick. Good luck -- Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94) mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/' #bofh excuse 14: sounds like a Windows problem, try calling Microsoft support |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. There are many specialized script around (especially perl scripts) which deal specifically with mailbox manipulation, if it's in a standard format (eg, mbox). In your specific case, I doubt that splitting the file using the NextPart lines will produce something useful or immediately usable as email. Some messages might not even have a NextPart line. Furthermore, that demarcation is not standard and depends on the MUA used to compose the mail. The particular string used in each email can be usually found in the Content-Type header. I have some messages in my inbox that use '===============12394855====.ALT' instead of NextPart. That said, one command to split a file using a regular expression as demarcation is csplit. To do what you want (but whose result might not be quite what you expect) you could use eg (GNU csplit, -z and -b seem to be nonstandard) $ csplit -z -f 00000 -b '%04d.txt' bigfile.txt '/---Next_Part/' '{*}' The above command will create a number of files 000000000.txt, 000000001.txt, etc., each containing the text between two successive '---Next_Part' lines. If the above does not suit your needs, then provide some sample input and expected output (or look for some specific mailbox manipulation tools). -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 3/16/2008 10:55 AM, 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 > ------------------- ----- ---- -- - > it sounds like all you need is something like: awk '/---Next_Part/{outfile="foo" ++cnt ".txt"} { print > outfile }' infile Ed. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 2008-03-16, superdu (nobody@cares) <superdu> 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 > If you have formail, you might use it to split the mail files. |
|
![]() |
| Outils de la discussion | |
|
|