Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-14-2007, 08:39 AM   #1
Registered: Apr 2003
Location: Reading, Berkshire, IN-GER-LUND!!!
Distribution: Mandriva 2006
Posts: 228

Rep: Reputation: 30
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?

Old 01-14-2007, 09:26 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734Reputation: 734
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:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting 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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression help. "?" m4a1rifle Linux - Newbie 25 03-05-2008 11:09 AM
Regular expression to match 4 or more alpha characters sixerjman Programming 15 11-27-2006 12:03 AM
Don't match a regular expression dakensta Programming 7 09-21-2006 03:48 AM
perl regular expression a char match richikiki Programming 8 07-19-2006 03:37 AM

All times are GMT -5. The time now is 10:33 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration