LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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
 
Thread Tools
Old 10-21-2003, 06:50 AM   #1
miknight
Member
 
Registered: Oct 2002
Location: Sydney, Australia
Distribution: Gentoo, Ubuntu, Debian
Posts: 184
Thanked: 0
Question Multi-file search and replace?


[Log in to get rid of this advertisement]
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!
miknight is offline     Reply With Quote
Old 10-21-2003, 07:10 AM   #2
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507
Thanked: 0
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 07:12 AM..
jkobrien is offline     Reply With Quote
Old 10-21-2003, 07:13 AM   #3
druuna
Senior Member
 
Registered: Sep 2003
Location: netherlands
Distribution: lfs
Posts: 3,269
Thanked: 78
Some thing like this (pseudo code):

cd /directory/to/search/

for THESE in `ls <find_string>`
do
-- your search & replace on file ${THESE}--
done
druuna is offline     Reply With Quote
Old 10-21-2003, 07:25 AM   #4
yapp
Member
 
Registered: Apr 2003
Location: Netherlands
Distribution: SuSE (before: Gentoo, Slackware)
Posts: 613
Thanked: 0
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
yapp is offline     Reply With Quote
Old 10-21-2003, 07:45 PM   #5
miknight
Member
 
Registered: Oct 2002
Location: Sydney, Australia
Distribution: Gentoo, Ubuntu, Debian
Posts: 184
Thanked: 0

Original Poster
Cheers guys I'll try some of these out.
miknight is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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


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 01:13 AM
search and replace in every file Thinking Programming 3 07-30-2005 06:50 PM
Looking for a multiple file search and replace tool, prefer graphical haimeltjnfg Linux - Software 6 02-02-2005 11:53 PM
Script to search and replace in text file - kinda... jeffreybluml Programming 45 11-07-2004 06:37 PM
Search and replace text in file using shell script? matthurne Linux - Software 2 11-02-2004 11:11 AM


All times are GMT -5. The time now is 11:45 PM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration