Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    how to yank (and even cooler replace) a line in a bunch of files

    I have a file that is in almost all my /home web accounts, here:


    in that file is a line I want to get rid of:

    <script id="jslocal" language="JavaScript" type="text/javascript" src="/site-local/local.js"></script>

    is there a simple shell script that would recurse all /home/xxx/public_html directories, and then yank this line (it will always be exactly the same)

    and better yet, for future, is there any way I can REPACE that line with another.. for now I'd be happy to get rid of it

    Thank you, if you need PHP help, go over to php builder dot com - *that* I can help you with I am sfullman over there

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    find /home/account*/public_html/ -type f -name "cms3.0.php" | while read FILENAME; do sed '/<script id="jslocal" language="JavaScript" type="text\/javascript" src="\/site-local\/local.js"><\/script>/c // PLACEHOLDER' ${FILENAME};done
    - Be sure to escape the /
    - If the result is to your liking, (watch out for multiple matches per file), then call sed with sed -i
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Sep 2007
    Silver Spring, MD

    Perl response

    find /home/account????/public_html/ -name cms3.0.php -exec perl -pi -e 's/<script id="jslocal" language="JavaScript" type="text\/javascript" src="\/site-local\/local.js"><\/script>/this works pretty nice/' {} \;

    This works in much the same way as the example given above except a perl script is used.

    So much we can learn from one another, I love this site.


  4. $spacer_open

Posting Permissions

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