LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2006, 10:39 AM   #1
mastro
LQ Newbie
 
Registered: Apr 2006
Posts: 2

Rep: Reputation: 0
Question using sed to parse large directory


Hello ppl,

I'm trying to use sed to parse a large directory of html files and remove a key word ex. 'wow' and then apply the change to the same html file, instead of writing it somewhere else.

So any help on how the syntax might look would be very much appreciated


Thanks
 
Old 04-13-2006, 10:48 AM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
How about this:
Code:
sed -e 's/wow/foo/g' -i .backup *.html
It will go through all .html files in the current directory, create a backup file with a .backup extension, then modify each file in place by substituting each instance of "wow" with "foo". Note you probably want to make the regex as precise as possible to avoid accidental unintentional changes (e.g. "s/man/boy" would turn "woman" into "woboy"). You can use
Code:
sed -f /path/to/file -i .backup *.html
to use the given file as your sed script.

(Disclaimer: these options are for BSD sed, but I believe they're the same for GNU sed.)
 
Old 04-13-2006, 10:58 AM   #3
mastro
LQ Newbie
 
Registered: Apr 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Taylor for the fast reply! Works like a charm
 
  


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
untar a single directory of a large taiwf Linux - General 1 02-22-2006 02:53 AM
Kernel source directory way too large Ahmed Linux - Software 3 12-28-2005 06:27 AM
using sed to parse emails dnardoni Programming 1 12-08-2005 03:10 AM
I need to parse a word: awk or sed? mehesque Programming 5 07-27-2004 04:23 PM
Parse a filename with awk and sed chrisk5527 Programming 2 06-08-2004 06:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:57 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
Open Source Consulting | Domain Registration