LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack Search this Thread
Old 03-18-2004, 07:02 AM   #1
philipina
Member
 
Registered: May 2003
Posts: 77

Rep: Reputation: 15
Replace a string including simple quotes.


Hello,

I have a string like " '2','asds','ddqw','NULL','qwsd' "
and I would like replace 'NULL' by NULL (without quote).

I tried the next :

nullString="'NULL'"
nullString2="NULL"
#Replace "'NULL'" by "NULL" to avoid error with mysql
sed -e 's/"$nullString"/"$nullString2"/g' mysql.txt > mysql2.txt
and
sed -e 's/$nullString/$nullString2/g' mysql.txt > mysql2.txt

and this is not working, there is no difference between both files!

how can I do that.
Is it possible to directly work with the string instead of a file?

Thanks in advance.
 
Old 03-18-2004, 07:21 AM   #2
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: fedora, slackware, suse
Posts: 447

Rep: Reputation: 31
Hope the following helps:

$ < mysql.txt sed s/\'NULL\'/NULL/
" '2','asds','ddqw',NULL,'qwsd' "
$ cat mysql.txt
" '2','asds','ddqw','NULL','qwsd' "
$ < mysql.txt sed s/\'NULL\'/NULL/
" '2','asds','ddqw',NULL,'qwsd' "
$
 
Old 03-18-2004, 07:38 AM   #3
philipina
Member
 
Registered: May 2003
Posts: 77

Original Poster
Rep: Reputation: 15
Thanks,

This is working, but only for the first 'NULL'.
Is it possible to make recursive to change all 'NULL' string in my file.

Thanks.
 
Old 03-18-2004, 07:40 AM   #4
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: fedora, slackware, suse
Posts: 447

Rep: Reputation: 31
Sorry, you only had one 'NULL' in your example. What I showed should do the first 'NULL' in each line. You need to append a g ... like this:

$ <mysql.txt sed s/\'NULL\'/NULL/g
 
Old 03-18-2004, 08:01 AM   #5
philipina
Member
 
Registered: May 2003
Posts: 77

Original Poster
Rep: Reputation: 15
Thank it works!
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace string Johng Programming 9 01-13-2010 04:50 AM
replace a substring with another string in C zeppelin Programming 21 11-09-2009 09:59 PM
How can I replace this string with another using sed? dave4545 Programming 7 01-27-2006 10:58 AM
GCC - including <string.h> (won't work) mymojo Linux - Newbie 3 10-17-2003 05:58 PM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM


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