bash script for finding and replacement in any web page code (.htm file)

Discussion in 'Programming/Scripts' started by vl72, Feb 19, 2011.

  1. vl72

    vl72 New Member

    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:
    # 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.
    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?

Share This Page