LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 04-12-2007, 11:13 AM   #1
Silvermask
LQ Newbie
 
Registered: Apr 2007
Distribution: Ubuntu Edgy
Posts: 1

Rep: Reputation: 0
Smile Simple sed problem need help


Hallo guys this is my first time to post a Q. so you all know that i hopefully wait your replies and help too and thanks for you time

the problem is i need to use sed to replace the "$database.class.php" with "mysql.class.php"

of course i created a script to do that it is code is:
########################################################
#!/bin/bsh
for file in $(find . -type f)
do
cat $file |sed "s/$database.class.php/mysql.class.php/g" > $file.new
mv $file.new $file
done
########################################################
and of course it didn't work as expected
so i tried to use skip char. but i don't know how

so please correct this line for me to the a replacement in the right way

and explanation will be appreciated too

thanks all

Silver
 
Old 04-12-2007, 12:31 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,345

Rep: Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945Reputation: 1945
$ and . are special characters. escape them using a \ before them. most notably $ represents the end of a line so can never be anything other than the last term in a string...
 
Old 04-12-2007, 01:15 PM   #3
MOS JEFF-INITELY
Member
 
Registered: Sep 2006
Distribution: Windows .. MUAHAHAHA
Posts: 66

Rep: Reputation: 15
instead of:
Quote:
Originally Posted by Silvermask
Code:
cat $file |sed "s/$database.class.php/mysql.class.php/g" > $file.new
mv $file.new $file
try this:
Code:
sed "s/\$database\.class\.php/mysql\.class\.php/g" $file >> $file
what was added: escape characters and append instead of having to create a temp file
 
  


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
Using "sed" - a simple explanation needed midiox Linux - Newbie 2 04-03-2006 06:47 AM
Simple question about sed or awk setianusa Programming 2 09-16-2005 03:57 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
Simple Text Reformat (sed and grep) mikefazz Programming 2 08-31-2004 07:38 PM
using sed, simple question bobthebat Programming 3 04-30-2001 10:01 PM


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