Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 08-14-2003, 09:49 AM   #1
Registered: Oct 2002
Location: At my desk...
Distribution: RedHat, Fedora, Ubuntu
Posts: 344

Rep: Reputation: 30
Question Regular Expression Help

I am having some trouble rebuilding a database or two via a mysql dump. The problem is that some non-escaped single quotes have made their way into certain fields.

So I am writing a script that will fix this... here is my sed command:

sed "s/\([A-Z|a-z|0-9]\)'\([A-Z|a-z|0-9]\)/\1\\\'\2/" $1 > /tmp/$1

This basically changes anything like "abc's" to "abc\\'s" or "123's" to "123\\'s". Now the problem is that this sed command only alters one occurrence within each line. There are multiple occurrences in each line...

So how do I make this alter multiple occurrences found in each line?

Last edited by WeNdeL; 08-14-2003 at 09:50 AM.
Old 08-14-2003, 10:08 AM   #2
Registered: Oct 2002
Location: At my desk...
Distribution: RedHat, Fedora, Ubuntu
Posts: 344

Original Poster
Rep: Reputation: 30
wow... rocket science we have here...

make the command look like this:

sed "s/\([A-Z|a-z|0-9]\)'\([A-Z|a-z|0-9]\)/\1\\'\2/g" $1 > /tmp/$1

notice the global "g" that was added...


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with regular expression aecaudel Programming 6 11-04-2005 05:28 AM
Need help with Regular Expression subaruwrx Linux - Newbie 6 09-04-2004 07:48 PM
Anyone know regular expression? ahhua Linux - Software 1 12-04-2003 08:13 AM
Regular Expression slizadel Programming 4 07-28-2003 05:16 AM
regular expression gumby Programming 3 07-15-2003 12:13 PM

All times are GMT -5. The time now is 06:54 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