If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > Perl script_Text inclusion in n-files

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-25-10, 19:44
bcramer bcramer is offline
Registered User
 
Join Date: Mar 2010
Location: Sao Paulo Brazil
Posts: 2
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 19:49.
Reply With Quote
  #2 (permalink)  
Old 04-02-10, 19:00
spacebar spacebar is offline
Registered User
 
Join Date: Feb 2006
Posts: 73
Reply With Quote
  #3 (permalink)  
Old 04-09-10, 17:36
sco08y sco08y is offline
Registered User
 
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 17:47.
Reply With Quote
  #4 (permalink)  
Old 04-12-10, 08:03
bcramer bcramer is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On