Sponsored Content
Top Forums Shell Programming and Scripting Perl script, how can I use this scipt in different folders Post 302401913 by luhaiming on Monday 8th of March 2010 08:56:58 AM
Old 03-08-2010
Perl script, how can I use this scipt in different folders

Hello,
I am a new programmer and currently having some difficulties writing a script. Your help will be very appreciated. In general, I have the below script running in one folder and and can get results from "OUPUT" file in the same folder. My question is I have several hundreds folder which all contain file "OUTPUT". How can I modify my below script to extract the results from all the OUTPUT file?
Thanks all in advance

Code:
#!/usr/bin/perl




# open file
  open FILE, "OUTPUT";
  @file = <FILE>;
  close FILE;

 # scan file
  $stop = scalar(@file);
  for ($n_line = 0; $n_line <= $stop-1; $n_line++) {
  $line = $file[$n_line];

if ($line=~/trace\/3\s*(\d.\d+E\-\d+)/) {
$average_pressure=$1;
open result1, ">>../pressure.txt";
#print  "$average_pressure\n";
print result1 "$average_pressure\n";
close result1; 
}

if ($line=~/trace\/3\s*(\d.\d+E\+\d+)/) {
$latt_length=$1;
open result2, ">>../lattice_vector.txt";
#print  "$latt_length\n";
print result2 "$latt_length\n";
close result2; 
}

if ($line=~/Average cell vectors\s*r.m.s. fluctuations /) {
chomp($file[$n_line + 2]);
	@matrix_line1 = split(/ +/, $file[$n_line + 2]);
        chomp($file[$n_line + 3]);
        @matrix_line2 = split(/ +/, $file[$n_line + 3]);
        chomp($file[$n_line + 4]);
        @matrix_line3 = split(/ +/, $file[$n_line + 4]);
		open result2, ">>../lattice_vector_error.txt";
#print  "$matrix_line1[4]\n";
print result2 "$matrix_line1[4]\n";
close result2; 
}

if ($line=~/Average pressure tensor\s*r.m.s. fluctuations/) {
chomp($file[$n_line + 2]);
	@matrix_line1 = split(/ +/, $file[$n_line + 2]);
        chomp($file[$n_line + 3]);
        @matrix_line2 = split(/ +/, $file[$n_line + 3]);
        chomp($file[$n_line + 4]);
        @matrix_line3 = split(/ +/, $file[$n_line + 4]);
#print "@matrix_line1\n @matrix_line2\n @matrix_line3\n";
$pressure_error=($matrix_line1[4]+$matrix_line2[5]+$matrix_line3[6])/3;
#print "$pressure_error\n";
open result1, ">>../pressure_error.txt";
print result1 "$pressure_error\n";
close result1; 
}

}


Last edited by pludi; 03-08-2010 at 10:07 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scipt to do login

I want a script which will run in the background. $ sh s.sh& 523 Then this script should provide input to the Login command. $ login login: i.e instead of the user typing in the username and password, the script running in the background should provide the username and password assuming... (1 Reply)
Discussion started by: rahulrathod
1 Replies

2. UNIX for Dummies Questions & Answers

Finding out process id in a scipt

Hi, If in a shell script i write a command ls > bla & ls The output is redirected to bla and the next ls starts as first one is going on in background. I want to find the PID of the first command. Thanks in advance (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

3. UNIX for Dummies Questions & Answers

UNIX/MS-DOs scipt

Is any one who know a good tutorial for Unix bash script and Ms-Dos scipt?? if yes, if is possible to upload it or give me the link??? What is the difference betwwen uvix and ms-dos script?? (1 Reply)
Discussion started by: Tom2
1 Replies

4. Shell Programming and Scripting

trigger a script based on the run status of another scipt

Im a newbee.. I have a script which runs few times daily. I want to write another script which should pick up the latest log generated from the last run of the first job and trigger a thrid script if the first script runs successfuly. Please help... Cheers (1 Reply)
Discussion started by: Athena
1 Replies

5. Shell Programming and Scripting

cant get a counter to work in bash scipt, this is calling expect script

I have looked high and low, tryed lots of diffrent things but cant get a simple counter to work right. what i need is to increase a count ever time it finishes the test, pass or fail. example TEST PASS 1, NEXT TEST PASS 2, I curently have set foo o while {$foo <=5} { incr foo puts... (1 Reply)
Discussion started by: melvin
1 Replies

6. Shell Programming and Scripting

help writing a scipt to search for errors.

Hi, I am a beginner unix user. I would appreciate any help you guys can provide me with. What I am looking to do is the following. I have a log file that gets generated every morning. Example: /home/me/folder/temp.log temp.log will say "Socket connected" if the connection was successful,... (4 Replies)
Discussion started by: Jeffenri
4 Replies

7. UNIX for Advanced & Expert Users

sysbase scipt error

Hi All, when is run this manually it work's i am UNable to get the proper .sql so that i can use this in my input file. I need to do this way only bcz of requirment. Sample script isql -Sxxx -Usa -Pyyyy -D master -o "abc_script.sql" << EOF echo USE master >> "abc_script.sql"... (1 Reply)
Discussion started by: oracle_coorgi
1 Replies

8. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

9. Shell Programming and Scripting

Validating uppercase/lowercase of user input with perl compared to unix folders

Hi, I need to copy files from a source directory to a destination directory in unix. I'm using the file::copy for the actual copy. The problem is that the source and dest directories are supplied by different users, who might type the name of the directories in various combinations of lower... (6 Replies)
Discussion started by: Furou
6 Replies

10. UNIX for Dummies Questions & Answers

How many times did the scipt ran?

Hi, Can we able to identify how many times any script was ran per day/week/month/year wise (2 Replies)
Discussion started by: penqueen
2 Replies
RMF(1)								     [nmh-1.5]								    RMF(1)

NAME
rmf - remove an nmh folder SYNOPSIS
rmf [+folder] [-interactive | -nointeractive] [-version] [-help] DESCRIPTION
Rmf removes all of the messages (files) within the specified (or default) folder, and then removes the folder (directory) itself. If there are any files within the folder which are not a part of nmh, they will not be removed, and an error will be produced. If the folder is given explicitly or the -nointeractive option is given, then the folder will be removed without confirmation. Otherwise, the user will be asked for confirmation. If rmf can't find the current folder, for some reason, the folder to be removed defaults to `+inbox' (unless overridden by user's profile entry "Inbox") with confirmation. If the folder being removed is a subfolder, the parent folder will become the new current folder, and rmf will produce a message telling the user this has happened. This provides an easy mechanism for selecting a set of messages, operating on the list, then removing the list and returning to the current folder from which the list was extracted. If rmf s used on a read-only folder, it will delete all the (private) sequences (i.e., "atr-seq-folder" entries) for this folder from your context without affecting the folder itself. Rmf irreversibly deletes messages that don't have other links, so use it with caution. FILES
$HOME/.mh_profile The user profile PROFILE COMPONENTS
Path: To determine the user's nmh directory Current-Folder: To find the default current folder Inbox: To find the default inbox SEE ALSO
rmm(1) DEFAULTS
`+folder' defaults to the current folder, usually with confirmation `-interactive' if +folder' not given, `-nointeractive' otherwise CONTEXT
Rmf will set the current folder to the parent folder if a subfolder is removed; or if the current folder is removed, it will make "inbox" current. Otherwise, it doesn't change the current folder or message. BUGS
Although intuitively one would suspect that rmf works recursively, it does not. Hence if you have a sub-folder within a folder, in order to rmf the parent, you must first rmf each of the children. MH.6.8 11 June 2012 RMF(1)
All times are GMT -4. The time now is 02:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy