Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I've been trying to remove the unneeded part of the header in stored e-mails so that they are easier to read. In DOS I can use rmheader.exe which will leave just a few parts such as "Subject:", "To:", "From:", "Date:", or whichever I specify. I am unable to find such a utility for linux. I tried sed, but that is very difficult for me and perhaps it is a bad approach for an amateur. (I'm still dizzy from that one!)
Can someone suggest a utility or script which I can use?
The e-mail files are in the form of sequential hex numbers eg "00001a.eml" but obviously i could change that if there was any advantage.
perl -ne 'if (/^\s*$/) {$b=1;} print if (/^(Subject|From|To|Date|Cc|Bcc):/||$b);' message.file
This will print the modified message on standard output. You can re-direct that to a new file as you like, or if you prefer to modify the original file in-place like this:
Code:
perl -i -ne 'if (/^\s*$/) {$b=1;} print if (/^(Subject|From|To|Date|Cc|Bcc):/||$b);' message.file
Of course you don't need to type all that in every time. You can put it in a file, make that executable and use it like any other program:
Code:
#!/usr/bin/perl -i -n
if (/^\s*$/) {$b=1;}
print if (/^(Subject|From|To|Date|Cc|Bcc):/||$b);
Remove the -i from the first line if you don't want it to modify files in place.
I don't know anything about perl, but now I have a little start to fool with in a useful way. This btw was my first post and boy am I pleased! Thanks again for going to the trouble of doing that script.
I just installed procmail to see if it has formail in the lib - it does. Actually procmail looks like a pretty useful package. Thanks for the tip Berhanie!
As for trickykid's suggestion of using grep and egrep, I had no idea that those utilities could be used in that fashion. I use a watered down (but extremely useful) version of those in DOS and they don't do anything like that. Jeesh! If you guys come up with any more suggestions, I won't get any work done ... :(
How about extracting email headers' IP and Domain values all dumped in a text file, how do I write the code?
I have tons of email messages that I need to extract and only need to know their IPs and domain names were found.
Quote:
Originally Posted by matthewg42
A little perl one-liner can do it with some ease:
Code:
perl -ne 'if (/^\s*$/) {$b=1;} print if (/^(Subject|From|To|Date|Cc|Bcc):/||$b);' message.file
This will print the modified message on standard output. You can re-direct that to a new file as you like, or if you prefer to modify the original file in-place like this:
Code:
perl -i -ne 'if (/^\s*$/) {$b=1;} print if (/^(Subject|From|To|Date|Cc|Bcc):/||$b);' message.file
Of course you don't need to type all that in every time. You can put it in a file, make that executable and use it like any other program:
Code:
#!/usr/bin/perl -i -n
if (/^\s*$/) {$b=1;}
print if (/^(Subject|From|To|Date|Cc|Bcc):/||$b);
Remove the -i from the first line if you don't want it to modify files in place.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.