Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Location
    Sao Paulo Brazil
    Posts
    2

    Unanswered: Perl script_Text inclusion in n-files

    Dear list participants,

    I need to include 9 to 10 lines at the begining of several text files.
    Each file have a name with sequential numbers containing molecule's cartesian coordinates:
    example

    molecule 1 molecule 2 etc

    file1_1.txt file2_1.txt
    file1_2.txt file2_2.txt
    .......... .......
    .......... .......
    file1_50.txt .......
    file2_130.txt

    As you can see in this example, the directory of molecule 1 has 50 files, dir of molecule 2 has 180 files, etc

    All the files have cartesian coordinates (x,y,z) presented as the example below:
    --------------------------------------
    C 0.000000 0.000000 0.000000
    S 1.544083 0.000000 0.000000
    S -1.544083 0.000000 0.000000
    --------------------------------------

    The objective is to use a Perl script that includes 9 or more comand lines at the begining of each file.
    This text (that are the calculation program lines) is the same for all the files for all molecules.
    The last line ends with an "*" .

    Complete example of the final file:
    -------------------------------------
    #*******MolID=CS2
    !B3LYP TZVP TightSCF
    !Opt
    !NumFreq
    !SemiDirect
    %freq
    Increment 0.001
    end
    !XYZFile
    * xyz 0 1
    C 0.000000 0.000000 0.000000
    S 1.544083 0.000000 0.000000
    S -1.544083 0.000000 0.000000
    *
    -------------------------------------
    This is a simple example. The real files have molecules with 50 to 100 atoms presenting
    in some cases more than 300 conformations. Inother words, a manual input of the text file can easily
    represent 3000 or more files. This is unfeasible. A Perl script would make this calculations possible.

    Can somebody help me in providing this script in Perl (for linux)?

    Thank you
    Best regards

    Bruno

    PS.: I found a Perl script that writes the text at the end of a text file but you have to run it file per file.
    This does not meet my requirements.
    Last edited by bcramer; 03-25-10 at 20:49.

  2. #2
    Join Date
    Feb 2006
    Posts
    173
    Provided Answers: 1

  3. #3
    Join Date
    Oct 2002
    Location
    Baghdad, Iraq
    Posts
    697
    Quote Originally Posted by bcramer View Post
    Dear list participants,

    I need to include 9 to 10 lines at the begining of several text files.
    Honestly, sometimes Perl is overkill. Just use bash:

    Code:
    for i in *.txt; do cat header "$i" footer > "new/$i"; done
    Even in Winders you can do it:

    Code:
    for %%i in *.txt do type header > new\%i
    for %%i in *.txt do type %i >> new\%i
    for %%i in *.txt do type footer >> new\%i
    Last edited by sco08y; 04-09-10 at 18:47.

  4. #4
    Join Date
    Mar 2010
    Location
    Sao Paulo Brazil
    Posts
    2

    Talking Text inclusion

    Hi

    Thank you all for taking your time in helping me out.
    Bruno

Posting Permissions

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