LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Regular expression to match "^" then a number? (https://www.linuxquestions.org/questions/linux-newbie-8/regular-expression-to-match-%5E-then-a-number-519167/)

PsychosisNode 01-14-2007 08:39 AM

Regular expression to match "^" then a number?
 
Hi, I'm writing a simple shell script to pipe chat messages from tremulous (An IOQ3 engine based online game) through a TTS program. In Q3 syntax, the caret then a single number is used to change the text colour in the chat string (e.g. ^1Hello would appear as Hello). This is my problem, I need to remove all occurrences of the caret and number in each chatstring otherwise the TTS program would say "carrot one hello". I'm currently piping the output of tremulous through sed then to the TTS program.

I understand that ^ is a special character in regular expressions, and that \ is used to escape these. However when I use the command sed -n -u 'd/\^[0-9]/' which I read to be "delete every occurrence of the character "^" then exactly one number", however I get the following error: sed: -e expression #1, char 2: extra characters after command

I've read the sed manpages and various regular expression guides, but I'm still a total clueless nubcake. What am I doing wrong?

Cheers!
-PN

pixellany 01-14-2007 09:26 AM

sed -n means surpress printout unless specifically commanded. Thus, without a "p", you'll get nothing.

The "d" command deletes the entire line which contains the match--and it goes after the pattern to be matched.

To delete an instance of "^ + any number", I think it would look something like this:
cat <filename>|sed 's/\^[0-9]//' > <newfilename>

Here's a good tutorial on sed: http://www.grymoire.com/Unix/Sed.html#uh-8


All times are GMT -5. The time now is 11:41 PM.