View Single Post
Old 19th February 2011, 16:12
vl72 vl72 is offline
Junior Member
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question bash script for finding and replacement in any web page code (.htm file)

I want to write Bourne-shell script that will be to do finding and replacement in any web page code (.htm file) name of the tied folder in which have been saved pictures, .css, .js and other files.
This folder create a web browser when we save web page completely and has so name as web page and has ending '_files'.
I have many web pages where name of their folder are incorrect. Of course, my web browser shows these web pages without pictures.
I can count amount of web pages in a folder (/path) needed for me.
1) find /path -type f -name "*.htm*" -print | grep -c .htm or
find /path -type f -name *.htm | wc -l
I can get list of web pages.
2) ls /path *.htm > out-list

But I don't know how to assign the value from out-list (2) or result commands from pipeline (1) to a variable.
Then I want to do next:
# where variable 'list' is an amount of web pages
while [ $var -le $list ]
4) …......
8) …......

4) assign the 1st (then 2nd , etc. ) value from out-list (2) to variable 'webfile'
sed -n $var,+0p out-spisok
5) find the 1st string value '_files' in the 'webfile'
grep -m1 _files $webfile

6) For example, 'abracadabra_files' is an incorrect folder in the 'webfile'
I must to know start and end position 'abracadabra' without ending '_files', “cut” name of the incorrect folder and assign it to the variable 'finder'
finder = 'abracadabra'
BTW, name of a folder before '_files' is between '=”' and '_files' in any web page code.
7) foldernew = $webfile (without '.htm')
' foldernew' is equal with name of the tied folder without ending '_files' in the folder '/path'
8) find and replace in the 'webfile' and save result in the 'webfile-out'
sed s/$finder/$foldernew/g $webfile > $webfile-out

Can anybody help me?
Reply With Quote
Sponsored Links