HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   bash script for finding and replacement in any web page code (.htm file) (http://www.howtoforge.com/forums/showthread.php?t=51529)

vl72 19th February 2011 16:12

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.
HOW TO DO THIS????
Then I want to do next:
3)
var="1"
# where variable 'list' is an amount of web pages
while [ $var -le $list ]
do
4) …......
8) …......
var=$[$var+1]
done

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.
HOW TO DO THIS????
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?


All times are GMT +2. The time now is 08:48.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.