Find the answer to your Linux question:
Results 1 to 2 of 2
i have a bash script like this: Code: #!/bin/bash # ALL HTML FILES FILES="*.html" # for loop read each file for f in $FILES do INF="$f" OUTF="$f.out.tmp" # replace javascript ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2012
    Posts
    1

    bash scripting to remove certain text


    i have a bash script like this:

    Code:
    #!/bin/bash
    # ALL HTML FILES
    FILES="*.html"
    # for loop read each file
    for f in $FILES
    do
    INF="$f"
    OUTF="$f.out.tmp"
    # replace javascript
    sed '/<!--fff309/,/<!--\/fff309-->/d' $INF > $OUTF
    /bin/cp $OUTF $INF
    /bin/rm -f $OUTF
    done
    the html is look like this:

    Code:
    <html>
    <body>
    <div>some normal html code</div>
    <!--fff309-->
    some javascript code goes here...
    <!--/fff309-->
    
    <div>
    some other html....
    </div>
    </body>
    </html>
    the bash script work, however it remove all the html part below the
    Code:
    <!--/fff309-->
    so it become:

    Code:
    <html>
    <body>
    <div>some normal html code</div>
    is there anyway to do so that it only remove the part:

    Code:
    <!--fff309--> ...  <!--/fff309-->
    GNU sed version 4.2.1
    uname -a:
    Linux abc.com 2.6.32-279.14.1.el6.x86_64 #1 SMP Tue Nov 6 23:43:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

    Thanks

  2. #2
    Linux Newbie
    Join Date
    Aug 2006
    Posts
    124
    Hi.

    I checked your example and your sed line in a terminal, and it works. Try removing the 2 lines,
    Code:
    /bin/cp $OUTF $INF
    /bin/rm -f $OUTF
    and check if the ".out.tmp" files are OK

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •