LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-20-2005, 06:41 AM   #1
saggi_sam
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Rep: Reputation: 0
how to run a script on subfolder file in a folder


i have a folder 'root' with .html files in it. Want to run a script which should search and replace a string in all these .html files. this script should search these .htmls as well as any other .html file in subfolders of 'root'. So script should also search sub-folder of root folder.
 
Old 06-20-2005, 07:19 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
find 'root' -type f -iname "*.html" -print | while read file; do sed -i 's/regexp/replacement/g' "$file"; done

Yves.
 
Old 06-20-2005, 04:01 PM   #3
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
Or a slightly shorter version:-

Code:
find 'root' -type f -iname "*.html" -exec sed -i 's/regexp/replacement/g' '{}' \;
 
Old 07-12-2005, 05:10 AM   #4
saggi_sam
LQ Newbie
 
Registered: Jun 2005
Posts: 4

Original Poster
Rep: Reputation: 0
thnx...dear..it helped

rgds.
sumit
 
Old 07-12-2005, 08:30 PM   #5
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
Quote:
Originally posted by ahh
Or a slightly shorter version:-

Code:
find 'root' -type f -iname "*.html" -exec sed -i 's/regexp/replacement/g' '{}' \;
just out of curiousity and since I'm new to linux can someone explain what that code does? Thanks!
 
Old 07-13-2005, 05:04 AM   #6
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
Quote:
Originally posted by Centinul
just out of curiousity and since I'm new to linux can someone explain what that code does? Thanks!
Code:
find 'root' -type f -iname "*.html" -exec sed -i 's/regexp/replacement/g' '{}' \;
find - The name of a command to find files/directories.
'root' - The path of the diretory you weant to start searching in, e.g. /home/centinul
-type f - Find regular files.
-iname "*.html" - Do a case insensitive search to match <anything>.html
-exec - execute the following, up to the \;, once for each result of the search, replacing '{}' with the file name.


sed - The name of a command to edit text
-i - Do the editing in place, not to the console or another file.
's/regexp/replacement/g' - 'do a search and replace / look for text that matches this regular expression / replace it with this text / do it globally, dont stop at the first match'
 
  


Reply



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
How to run bat file from Unix script??? gopi_20us Programming 10 09-14-2010 09:15 AM
BASH Shell script : copying a file to multiple folder zamri Programming 14 04-29-2008 10:27 AM
starting script, init by copy/create file in (samba) folder? muab Linux - General 7 06-22-2005 06:02 PM
Why Do I need to run updatedb each time I search for a file or folder? lennysokol Linux - Software 4 05-30-2005 10:49 PM
making a script that will move a file or files in a trash folder Paxmaster Programming 5 12-12-2004 06:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:39 AM.

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
Open Source Consulting | Domain Registration