| Author |
Message |
Icarus Sparry *nix forums Guru
Joined: 19 Feb 2005
Posts: 342
|
Posted: Mon Feb 14, 2005 7:01 pm Post subject:
Re: sed substitute From -> From:
|
|
|
On 2005-02-14, Florian Reiser <dy@reiser-familie.de> wrote:
| Quote: | Me neither - i'm pretty much new to bash scripting.
More precise is
sed '1,5 s/^From /From: /'
Hey, it did the trick! The Header-lines didn't get deleted.
It couldn't have been the "g" - that just searches the whole file as much as
i know.
|
No, the 'g' causes ALL the matches on the current line to be changed,
rather than just the first. |
|
| Back to top |
|
 |
Florian Reiser *nix forums beginner
Joined: 14 Feb 2005
Posts: 6
|
Posted: Mon Feb 14, 2005 6:03 pm Post subject:
Re: sed substitute From -> From:
|
|
|
Hi Ed,
| Quote: | You're needlessly using cat twice
|
I had given it a thought ... and just kept it that way, not knowing any
better, due to the e-mail issue.
I must say it was not very performant in any way :)
| Quote: | do
sed '1,5 s/From /From: /' "$datei" > tmp
cp tmp "$datei" && rm tmp
|
Wow, that's a lot faster - of course! Especially when there are a lot of
e-mails!
And it works, just like Michael's solution.
I should have isolated this part of the script and let it run alone - i
guess the other parts of it did the deleting.
| Quote: | You might want to use "formail" <...
|
I thought there must be something like this - normally my problems
concerning e-mails popped up long ago somewhere else.
So thank's a lot again - it saved me from spending a lot more time on such a
little thing.
Greetings,
Florian Reiser |
|
| Back to top |
|
 |
Florian Reiser *nix forums beginner
Joined: 14 Feb 2005
Posts: 6
|
Posted: Mon Feb 14, 2005 5:51 pm Post subject:
Re: sed substitute From -> From:
|
|
|
Hi Michael,
| Quote: | I dont know what's wrong
|
Me neither - i'm pretty much new to bash scripting.
| Quote: | More precise is
sed '1,5 s/^From /From: /'
|
Hey, it did the trick! The Header-lines didn't get deleted.
It couldn't have been the "g" - that just searches the whole file as much as
i know.
Maybe it was the "^". The problem is i have more lines getting deleted
because of other issues and it's a bit difficult getting it sorted out.
Anyhow, thank you for your help!
Florian Reiser |
|
| Back to top |
|
 |
Ed Morton *nix forums Guru
Joined: 20 Feb 2005
Posts: 1073
|
Posted: Mon Feb 14, 2005 1:21 pm Post subject:
Re: sed substitute From -> From:
|
|
|
Florian Reiser wrote:
| Quote: | I have a lot of e-mails where the header got messed up (I'm trying to feed
Cyrus-IMAP with those mails and they don't get taken).
One of the problems is that there's a ":" missing in the "From:"-line, like
this:
From xy@domain.xyz
... instead of ...
From: xy@domain.xyz
I wrote a script using sed to substitute "From" with "From:" but instead of
subtituting it DELETES those lines! It ist supposed to subbstitute only in
the first 5 lines.
This is what it looks like:
for datei in *
do
cat $datei | sed '1,5 s/From /From: /g' | cat > tmp
cp tmp $datei && rm tmp
done
Can anyone point me to what's wrong ?
|
You're needlessly using cat twice and have a couple of other problems.
Try this:
for datei in *
do
sed '1,5 s/From /From: /' "$datei" > tmp
cp tmp "$datei" && rm tmp
done
and let us know what happens.
You might want to use "formail" to fix mail formatting problems instead
of writing your own scripts though. See http://www.procmail.org and
http://www.rt.com/man/formail.1.html for more information.
Ed
| Quote: | Thank's a lot,
Florian Reiser |
|
|
| Back to top |
|
 |
Michael Tosch *nix forums Guru
Joined: 21 Feb 2005
Posts: 539
|
Posted: Mon Feb 14, 2005 1:14 pm Post subject:
Re: sed substitute From -> From:
|
|
|
Florian Reiser wrote:
| Quote: | I have a lot of e-mails where the header got messed up (I'm trying to feed
Cyrus-IMAP with those mails and they don't get taken).
One of the problems is that there's a ":" missing in the "From:"-line, like
this:
From xy@domain.xyz
... instead of ...
From: xy@domain.xyz
I wrote a script using sed to substitute "From" with "From:" but instead of
subtituting it DELETES those lines! It ist supposed to subbstitute only in
the first 5 lines.
This is what it looks like:
for datei in *
do
cat $datei | sed '1,5 s/From /From: /g' | cat > tmp
cp tmp $datei && rm tmp
done
Can anyone point me to what's wrong ?
Thank's a lot,
Florian Reiser
|
I dont know what's wrong but you expression probably can do more than you intended.
More precise is
sed '1,5 s/^From /From: /'
or
sed '1,/^$/ s/^From /From: /'
--
Michael Tosch @ hp : com |
|
| Back to top |
|
 |
Florian Reiser *nix forums beginner
Joined: 14 Feb 2005
Posts: 6
|
Posted: Mon Feb 14, 2005 12:54 pm Post subject:
sed substitute From -> From:
|
|
|
I have a lot of e-mails where the header got messed up (I'm trying to feed
Cyrus-IMAP with those mails and they don't get taken).
One of the problems is that there's a ":" missing in the "From:"-line, like
this:
From xy@domain.xyz
.... instead of ...
From: xy@domain.xyz
I wrote a script using sed to substitute "From" with "From:" but instead of
subtituting it DELETES those lines! It ist supposed to subbstitute only in
the first 5 lines.
This is what it looks like:
for datei in *
do
cat $datei | sed '1,5 s/From /From: /g' | cat > tmp
cp tmp $datei && rm tmp
done
Can anyone point me to what's wrong ?
Thank's a lot,
Florian Reiser |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|