LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 10-21-2003, 05:50 AM   #1
miknight
Member
 
Registered: Oct 2002
Location: Sydney, Australia
Distribution: Gentoo, Ubuntu, Debian
Posts: 184

Rep: Reputation: 30
Question Multi-file search and replace?


Hi everyone,

I'd like to perform a search and replace through a whole bunch of files in one dir. What are some good ways of achieving this?

Thanks for any help!
 
Old 10-21-2003, 06:10 AM   #2
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
sed should be able to do what you want.

sed -i.bck 's/old/new/g' file_list

Last edited by jkobrien; 10-21-2003 at 06:12 AM.
 
Old 10-21-2003, 06:13 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Some thing like this (pseudo code):

cd /directory/to/search/

for THESE in `ls <find_string>`
do
-- your search & replace on file ${THESE}--
done
 
Old 10-21-2003, 06:25 AM   #4
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613

Rep: Reputation: 30
Code:
for file in *
do
  sed -e 's/search-pattern/replace-string/g' < "$file" > "$file.2"
  mv "$file.2" "$file"
done
or:

Code:
find /some/folder/ -name "*something*" | while
  read file
do
  .. some thing with $file here.
done
 
Old 10-21-2003, 06:45 PM   #5
miknight
Member
 
Registered: Oct 2002
Location: Sydney, Australia
Distribution: Gentoo, Ubuntu, Debian
Posts: 184

Original Poster
Rep: Reputation: 30
Cheers guys I'll try some of these out.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does anyone know of a bash script can search & replace txt in a file. jimwelc Linux - Newbie 6 09-15-2008 12:13 AM
search and replace in every file Thinking Programming 3 07-30-2005 05:50 PM
Looking for a multiple file search and replace tool, prefer graphical haimeltjnfg Linux - Software 6 02-02-2005 10:53 PM
Script to search and replace in text file - kinda... jeffreybluml Programming 45 11-07-2004 05:37 PM
Search and replace text in file using shell script? matthurne Linux - Software 2 11-02-2004 10:11 AM


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