[X-Unix] SED help

Charles Howse chowse at charter.net
Thu Nov 3 08:38:44 PST 2005


> I'm a rank beginner with command line editing.
> 
> The shell is tcsh.
> 
> I have a series of about 100 directories each with a "mailto" file
> containing a list of email addresses. I wish to add the same address
> to the end of each of the "mailto" files.
> 
> I've used "foreach" and "sed" to do replacements, but adding a new
> line has defeated me so far.
> 
> For replacements, I've had success with:
> 
> 
>> server 10# foreach file ( `find . -name mailto` )
>> foreach? cat $file |sed 's/something/else/g' > $file.tmp
>> foreach? mv $file.tmp $file
>> foreach? end
>> 
> 
> Thinking that a "\n" would insert as a new line, I tried to replace
> the last line of the mailto file with:
> foreach? cat $file |sed
> 's/'user1 at company.com'/'user1 at company.com'\n'user2 at company.com'/g' >
> $file.tmp
> 
> This ran the two addresses together with an "n" in the middle.
> 
> Any suggestions would be greatly appreciated.

If you have /bin/bash, and if *all* you want to do is add "me at privacy.net"
to the end of each of your mailto files, why not try this?

for file in `find . -name mailto` ;
    do echo "me at privacy.net" >> $file
done

You'll have to add the appropriate command to go through all your 100
directories, but try it on one of them, and maybe I can help with the
complete script.  BTW, I use bash, but it might work in tcsh.
You can even get this to prompt you for the email address when it runs, or
enter the address as a parameter.
I'm available to help if you want to try it.
See The Advanced Bash Scripting Guide: http://www.tldp.org/LDP/abs/html/



More information about the X-Unix mailing list