Register
It is currently Sun Apr 20, 2014 11:04 pm

replace script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sat Jan 31, 2009 4:08 am   

Joined: Tue Dec 11, 2007 10:21 pm
Posts: 20
hello does anyone have any ideea how to replace one ip in database with other ip using a script , i belive nano is good i know how to search and replace but i dont know how to do that in a line command. anyone can help?


Top
 Profile  
 PostPosted: Sat Jan 31, 2009 10:01 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
What kind of database?
If it's an SQL based on then you should just be able to do something like this:
Code:
mysql -uusername -ppassword database <<EOF
update tablename set column="newipadress" where column="oldipadress"
EOF

Replace username with the right one and password with the right one (-u and -p is not to be touched).
Also change newipadress to the new one and oldipadress to the old one. Change column to which columnname the adress is in and tablename to the correct table.

If it's a file you're going to change then there are several ways.
Code:
sed -i "s/oldipadress/newipadress/g" filename

This will change the file "filename"

You can use VIM for this also, open the file and write:
Code:
:%s/oldipadress/newipadress/g


or you can do it like this also
Code:
cat filename | replace "oldipadress" "newipadress" > newfilename


Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Sat Jan 31, 2009 4:54 pm   

Joined: Tue Dec 11, 2007 10:21 pm
Posts: 20
the sed option was working verry well , thank you a lot for your help.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP