Find the answer to your Linux question:
Results 1 to 8 of 8
Dear group, I need to add a license file to thousands of scripts. Can anybody point me in the right direction (PERL,SED,AWK)? Distro: Cent OS 3 Regards, g...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2005
    Posts
    2

    Inserting a license file into thousands of scripts


    Dear group,

    I need to add a license file to thousands of scripts. Can anybody point me in the right direction (PERL,SED,AWK)?

    Distro: Cent OS 3


    Regards,
    g

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    What do you mean exactly by this? Can you clarify what exactly you're trying to do.
    Thanks,
    Andy

  3. #3
    Linux User Stefann's Avatar
    Join Date
    Nov 2004
    Location
    Boise, ID
    Posts
    340
    Quote Originally Posted by lakerdonald
    What do you mean exactly by this? Can you clarify what exactly you're trying to do.
    Thanks,
    Andy
    I think insert
    # Liscence
    #blah blah
    at the beginning of every script file in a dir or something.
    Nothing is worse than ten penguins fighting over which is better, vi or emacs.
    Registered Linux User #404402
    Finally I'm back on LF after a long while.

  4. #4
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    OP, you're not going to be able to get much help with a description like that.

    You want to "add a license file" to scripts? Explain more and give an example.

  5. #5
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Chicago (USA)
    Posts
    1,028
    I think sed or awk is what you need.

  6. #6
    Just Joined!
    Join Date
    Dec 2005
    Posts
    2
    Sorry about the poor description. What I'm trying to do is add license text to the top of thousands of scripts. The license file is about 25 lines long and contains the comments for PHP. I need to add it to line 2 before any code. Please see below for an example.


    EXAMPLE SCRIPT:
    <?php
    phpinfo();
    ?>


    EXAMPLE LICENSE:
    /*
    * My license
    * this is about 25 lines long
    * copyright year organization
    */


    AFTER MERGE:
    <?php

    /*
    * My license
    * this is about 25 lines long
    * copyright year organization
    */

    phpinfo();
    ?>

  7. #7
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    Code:
    license-text=$&#40;cat license-file&#41;
    for file in "$list"
    do
    sed -i 2i"$license-text" "$file"
    done
    where license-file is the license file, and $list is a list of files to do this to

  8. #8
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    This thread explains how to use sed to insert into a text file: http://www.linuxforums.org/forum/post-322163.html

    Sounds like you can just cat the license file and insert it at the appropriate line in your scripts.

    edit: Nothing like being slow.

Posting Permissions

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