LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 08: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, 09:26 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:57 AM.

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
Open Source Consulting | Domain Registration