D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

[LUG] Sed experts wanted, perhaps?

 

Hi all,

I'm trying to write a little script that can read a file and invoke
twidge to tweet its contents to Twitter.

The # symbol, being a special character (I think) is the root the my
problems... and being Twitter, the # symbol is going to be used a fair
bit.

If I invoke twidge from the command line as this:
 $ twidge update "#generic #twitter #update"
then all is well. The # symbol(s) are wrapped up in "" nicely.

I haven't got to the reading-from-a-file bit yet, but here's what I have:

#!/bin/sh
# Send Twitter updates through Twidge
command="twidge update"
status="$@"
$command $status

As it is, if I have no # symbols, it will work fine... however pop a #
in there and it fails. It also fails with # symbols if I wrap the last
line as:
$command "$status"

As it is, if I escape the # symbols, then it works fine... so I crack
out sed...:
status=`echo "$@" | sed -e "s/#/\#/g"` ... fails
status=`echo "$@" | sed -e "s/\#/\\#/g"` ... fails (escaping the #
symbol in sed)
status=`echo "$@" | sed -e "s/\#/\\\#/g"` ... fails (escaping the #
symbol and the \ symbol in the replacement string)

Now, regexes of any nature have never been my strong point. I was
successful with
status=`echo "$@" | sed -e "s/~/#/g"` ... (replacing the ~ with the # symbol)
but I don't really want my text file(s) to all have ~ instead of #
symbols if I can get away with it.

Anybody got any ideas?

-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq