Minor editing of mass HTML files


 
Thread Tools Search this Thread
Top Forums Programming Minor editing of mass HTML files
# 1  
Old 02-10-2012
Minor editing of mass HTML files

Hello,

I'm manipulating a batch of about 2,000 HTML files. I just need to make some small changes, but to all the files at once.

For example, I want to delete the lines that have "embed_music" in all the files, or change all instances of the word "Paragraph" to "Absatz".

This is my pseudo-code:
Code:
open target folder of html files (/project/html/)
read in all html files
*do the stuff here:
check for lines containing "embed_music", if yes delete
string replace for words with "Paragraph" to "Absatz"
*
close folder

Is my logic correct? I'm attempting to do this with Python, would another language work better? Would appreciate any help or feedback!
# 2  
Old 02-10-2012
I guess I'd have gone with a simple shell script letting find, and sed do the hard work:


Code:
find /project/html -name "*html" | while read filename
do
    if [[ ! -f $filename- ]]    # if a backup exists, don't do anything
    then
        mv $filename $filename-     # make backup
        sed '/embed_music/d; s/Paragraph/Absatz/;' $filename- >$filename # make changes
    fi
done

Makes a backup of the original file (I like that safety net) and then makes the changes. If the backup file exists, no action is taken -- prevents overlaying your original file should something not work right and the script is run again.


Python certainly will work, but this I think is easiest.
# 3  
Old 02-11-2012
To Delete all line having word "embed_music" from files reside in DIR , Run below sed from base dir ..

Code:
# find .  -type f -exec sed -i '/embed_music/d;' {} \;


To Replace all "Paragraph" to "Absatz" , Run below sed from base dir .

Code:
 
#  find . -type f -exec sed -i 's/Paragraph/Absatz/' {} \;


OR Run both in one line as below from base dir

Code:
find . -type f -exec sed -i '/embed_music/d; s/shirish/shukla/g' {} \;


--Shirish Shukla
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Editing HTML with FTP access

Hello, I've got a similar problem. I want to add some lines before the ending of the <head> tags. How can I do that? Example.<head> <some website stuff here> <My stuff> <head> I'd like to do that automatically with ftp. Is it possible to activate a sort of syncing in order to update... (4 Replies)
Discussion started by: danogentili
4 Replies

2. Shell Programming and Scripting

Editing path in a HTML file using Perl

Hello I want to replace the path to which a hyperlink points to. I have a html file <TABLE BORDER CELLPADDING=7, border=0><TR><td>Jun-10-2013_03_19_07_AM</td><td>Ank_Insert_1</td><td><b>FAILED: 1</b></td><td><A ... (14 Replies)
Discussion started by: ankurk
14 Replies

3. Shell Programming and Scripting

editing single line in html file in perl script

Hi Folks, It is regarding the perl scripting. I have an html file(many files) which contains the below line in the body tag. <body> <P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P> </body> Now I want to read that html file through perl... (3 Replies)
Discussion started by: giridhar276
3 Replies

4. Shell Programming and Scripting

Rename mass files with text from first line

I have a few hundred text files that are currently numbered files. I would like to rename each one with the text from the first line in the file. I would prefer this is perl script rather than a one liner as it wil be after many alterations to the file via an existing script. Any help would be... (1 Reply)
Discussion started by: GWhizz
1 Replies

5. Shell Programming and Scripting

mass renaming files with complex filenames

Hi, I've got files with names like this : _Some_Name_178_HD_.mp4 _Some_Name_-_496_Vost_SD_(720x400_XviD_MP3).avi Goffytofansub_Some name 483_HD.avi And iam trying to rename it with a regular pattern. My gola is this : Ep 178.mp4 Ep 496.avi Ep 483.avi I've tried using sed with... (8 Replies)
Discussion started by: VLaw
8 Replies

6. Windows & DOS: Issues & Discussions

Windows mass copy files with same name in differnt folders

I have files existing with same names in the folders with date as display below c:\2010-09-10 <==== folder arr1.jpg arr2.jpg arr3.jpg arr4.jpg c:\2010-09-09 <==== folder arr1.jpg arr2.jpg c:\2010-09-08 <==== folder arr2.jpg arr3.jpg arr4.jpg ... (5 Replies)
Discussion started by: jville
5 Replies

7. UNIX for Dummies Questions & Answers

Need help to mass rename files

Hi. I've got 75 mp3s that have the word 'Émission' in their filename. They are all in this format: Émission bla1 bla1.mp3 Émission bla2 bla2.mp3 Émission bla3 bla3.mp3 etc... I would just like to mass replace 'Émission' by 'Emission'; basically replace 'É' with 'E'. The rest of the... (10 Replies)
Discussion started by: Kingzy
10 Replies

8. AIX

VI questions : mass changes, mass delete and external insert

Is it possible in VI to do a global change but take the search patterns and the replacement patterns from an external file ? I have cases where I can have 100,200 or 300+ global changes to do. All the new records are inside a file and I must VI a work file to change all of them. Also, can... (1 Reply)
Discussion started by: Browser_ice
1 Replies

9. Shell Programming and Scripting

Mass Change content in all files

Hi, Are there any sample scripts to change content like file paths, profile paths etc., from test version to production , instead of changing one by one, i would like to pass the in file (prod version/Test version) to convert to test or prod verions. any help is appreciated!! ~R (1 Reply)
Discussion started by: terala
1 Replies

10. UNIX for Dummies Questions & Answers

Easy way to mass rename files?

Hi. What is the easiest way to rename a bunch of files? For example taking all files ending in ".php3" and rename them to end in ".php" I could write a script to do this, but there is probably an easier way... Thanks! (17 Replies)
Discussion started by: Thermopylae
17 Replies
Login or Register to Ask a Question