LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices



Reply
 
Search this Thread
Old 01-14-2007, 09:39 AM   #1
PsychosisNode
Member
 
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?

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

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


Reply


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 12:09 PM
Regular expression to match 4 or more alpha characters sixerjman Programming 15 11-27-2006 01:03 AM
Don't match a regular expression dakensta Programming 7 09-21-2006 04:48 AM
perl regular expression a char match richikiki Programming 8 07-19-2006 04:37 AM


All times are GMT -5. The time now is 09:43 PM.

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