LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-19-2008, 01:24 AM   #1
wds
LQ Newbie
 
Registered: Mar 2006
Location: Jamaica Plain (Boston)
Distribution: LFS
Posts: 8

Rep: Reputation: 0
trouble backreferencing with sed


Hi all,

I'm running Fedora8 on an AMD x64 have some iterating text in a flat file I'd like to change, but keep the iteration.

For example, parts of my file say "Ge1:1 then some text, Ge1:2 then some more text...Ge1:22...."

I'd like to replace "Ge1:n" with "<sub>n</sub>" - basically, I'm formatting something in HTML and want to put the number after the colon into superscript and lose the "Ge1:"

I'm reading a sed tutorial (see link below) and came up with the following:

sed s/Ge1\:\([0-9]*\)/\<sub\>\1\<\\/sub\>/ a.txt > b.txt

But it doesn't replace anything.

When I run: sed s/Ge1\:[0-9]*\ /\<sub\>\<\\/sub\>/ a.txt > b.txt it works fine, but I lose "n"

Does anyone know why the "\1" isn't recognizing the "\([0-9]*\)" ?

http://www.grymoire.com/Unix/Sed.html

Thanks, William
 
Old 06-19-2008, 01:32 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
You haven't quoted the sed substitution, and the shell is eating the backslashes. Place quotes around your expression. Also, you can use a different substitution field delimiter to reduce the backslashes. Finally, don't backslash characters that don't need to be escaped.

Here's a solution:

Code:
sed 's-Ge1:\([0-9]*\)-<sub>\1<\/sub>-'
Note how I changed s/x/y/ into s-x-y-

Last edited by Mr. C.; 06-19-2008 at 08:16 PM.
 
Old 06-19-2008, 08:13 PM   #3
wds
LQ Newbie
 
Registered: Mar 2006
Location: Jamaica Plain (Boston)
Distribution: LFS
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks!

Thank you!
 
  


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
sed trouble hfawzy Programming 5 08-07-2006 10:37 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
Having some trouble with sed P0ldy Linux - General 6 01-04-2006 04:26 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


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

Main Menu
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