Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Need help with a sed command

Need help with a sed command
Thread Tools
Mac Elite
Join Date: Aug 2001
Location: Madison, WI
Status: Offline
Reply With Quote
Dec 8, 2004, 04:41 PM
 
My office's new voicemail system will forward .wav attachments to your email, if requested. The small problem is that they come across with a content boundary of
Content-Type: application/octet-stream; name="VM.WAV"

While this works, it shows an attachment that wants to be opened in iTunes.

When the same message is forwarded, it comes across as
Content-Type: audio/x-wav

These forwards show a quicktime controller in mail.app- much more desireable than sticking it all in iTunes. So- I should be able to stick a sed command in .procmailrc to rewrite these files with the more desireable Content-Type, and get attachments that play in mail.app. I'm able to do a simple sed that turns night into day:
sed -e s/night/day

But can't get a more complicated one to work. I think the problem is that the content I'm finding and replacing all contain the / in it, which is also sed's delimiter. I've tried delimiting it as \/ and `\/' per online references I've found, but it's never worked out. Procmail only logs "error while writing to "<my sed statement here>"

So to summarize, the intent is to have procmail call sed, who looks for a line like
Content-Type: application/octet-stream; name="VM.WAV"
and replaces it with
Content-Type: audio/x-wav

Can anyone tell me what that should look like? I've seen 2 dozen things it shouldn't look like today.....
OS X: Where software installation doesn't require wizards with shields.
     
Mac Elite
Join Date: Aug 2001
Location: Madison, WI
Status: Offline
Reply With Quote
Dec 9, 2004, 07:22 PM
 
The answer is that the sed I was using didn't do expressions like anything else I'd ever seen. It wanted every form of punctuation escaped. Most interesting was to get a literal /, it demands double escapes: \\/ .
OS X: Where software installation doesn't require wizards with shields.
     
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Dec 10, 2004, 10:11 AM
 
Originally posted by C.J. Moof:
The answer is that the sed I was using didn't do expressions like anything else I'd ever seen. It wanted every form of punctuation escaped. Most interesting was to get a literal /, it demands double escapes: \\/ .
Did you end up using a new version of sed? GNU maybe?
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Dec 11, 2004, 04:31 AM
 
sed uses 'basic regular expressions' which is a little different that grep or perl. If you look at the find panel in subethaedit it gives you a choice of 7 different flavors. I learned reg ex with bbedit and it drove me nuts when I later tried to use php's ereg_replace() or grep on the command line.


If I remember right sed can use other delimiters.

a quick grab from the man page that may not be helpful:

s/regular expression/replacement/flags
Substitute the replacement string for instances of the regular expression in the pattern space. Any character other than backslash or newline can be used instead of a slash to delimit the RE and the replacement.
     
Mac Elite
Join Date: Aug 2001
Location: Madison, WI
Status: Offline
Reply With Quote
Dec 12, 2004, 12:05 PM
 
'Basic regular expressions' vs grep/perl regex? I never realized there was more than one kind. Maybe I wouldn't have had so much trouble with this if I knew it might be this kind of regex, or that kind of regex.

I ended up using the same sed that came with the system I was working on (a Linux flavor, not OS X btw), I just finally deciphered it's rules by trial and error- digesting little bits and hacking around until I figured out what worked. For the record:

Code:
| sed -e s/Content\-Type\:\ application\\/octet\-stream\;\ name\=\"VM\.WAV\"/Content\-Type\:\ audio\\/x\-wav\;/
OS X: Where software installation doesn't require wizards with shields.
     
Mac Elite
Join Date: Aug 2001
Location: Madison, WI
Status: Offline
Reply With Quote
Dec 12, 2004, 12:06 PM
 
Ha! The forum's code tag doesn't turn off smilies? That's comical.
OS X: Where software installation doesn't require wizards with shields.
     
Dedicated MacNNer
Join Date: Nov 2004
Location: Stockholm, Sweden
Status: Offline
Reply With Quote
Dec 12, 2004, 01:56 PM
 
Originally posted by C.J. Moof:
Ha! The forum's code tag doesn't turn off smilies? That's comical.
it does if you check the Disable Smilies in This Post option.
     
Mac Elite
Join Date: Aug 2001
Location: Madison, WI
Status: Offline
Reply With Quote
Dec 13, 2004, 03:06 PM
 
Sure, but when I'm already designating content as code, "no smilies here" ought to be implied.
OS X: Where software installation doesn't require wizards with shields.
     
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Dec 13, 2004, 10:40 PM
 
I think the lesson here is "computers are hard"
     
Mac Enthusiast
Join Date: Mar 2004
Status: Offline
Reply With Quote
Dec 14, 2004, 04:09 AM
 
Originally posted by Gavin:
I think the lesson here is "computers are hard"
regex or smilies?
     
Professional Poster
Join Date: Jun 2000
Status: Offline
Reply With Quote
Dec 14, 2004, 08:08 PM
 
It's so AOL users won't be afraid of the code tag.

Code:
#include <aol.h> int LOL!!11(){ :) }
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:09 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2