LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
 
Search this Thread
Old 06-10-2003, 09:36 AM   #1
dexter_modem
Member
 
Registered: Oct 2002
Location: Chicago
Distribution: slackware > redhat
Posts: 69

Rep: Reputation: 15
find and replace in files from command line


I have about 60+ files that have a login and password in them lets just say its

DBI->connect ('davesbedroom',"masterman","secluded",'Oracle');

I need to change everyone of those files to read

DBI->connect ('davesbedroom',"masterman","jojo",'Oracle');

How can I do this from the linux command line easy?
 
Old 06-10-2003, 09:46 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 28,407
Blog Entries: 54

Rep: Reputation: 3233Reputation: 3233Reputation: 3233Reputation: 3233Reputation: 3233Reputation: 3233Reputation: 3233Reputation: 3233Reputation: 3233Reputation: 3233Reputation: 3233
use "sed -e "s/something/something completely different/g"", maybe do: "for i in (list of files); do cp "$i" "$i.backup"
cat "$i" | sed -e "s/masterman/jojo/g" > "$i.tmp"; mv -f "$i.tmp" "$i"
done; find . -type f -name \*.backup > tarlist; tar -czf backups_$$.tgz -T tarlist --remove-files; rm -f tarlist"
 
Old 06-10-2003, 10:45 AM   #3
dexter_modem
Member
 
Registered: Oct 2002
Location: Chicago
Distribution: slackware > redhat
Posts: 69

Original Poster
Rep: Reputation: 15
Hey that works great!! Where did you learn to shell script so well? give a young jedi some help. is there an oreilly book you read?
 
Old 06-10-2003, 11:06 AM   #4
dexter_modem
Member
 
Registered: Oct 2002
Location: Chicago
Distribution: slackware > redhat
Posts: 69

Original Poster
Rep: Reputation: 15
problem is i can do the script for one file.. having a hard time doing the (list of file); i keep getting
./somescript.sh: line 3: syntax error near unexpected token `('
./somescript.sh: line 3: `for i in (bucka,fucka);'
 
Old 06-10-2003, 11:27 AM   #5
dexter_modem
Member
 
Registered: Oct 2002
Location: Chicago
Distribution: slackware > redhat
Posts: 69

Original Poster
Rep: Reputation: 15
i fixed it... i just picked up oreilly's "linus in a nutshell a desktop reference" and i am a scripting mad man!!
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python: find defined text string in a file, and replace the whole line Dark Carnival Programming 6 05-22-2007 06:02 AM
Can't find command line barbra Linux - Newbie 3 12-28-2004 02:17 PM
Command line tools to Find files with specific text naps Linux - Software 5 11-15-2004 04:46 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
how to find a looooooooong command line acid_kewpie Linux - General 6 11-20-2002 01:37 PM


All times are GMT -5. The time now is 09:36 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration