Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-03-2012
Registered User
 
Join Date: Oct 2009
Posts: 162
Thanks: 17
Thanked 0 Times in 0 Posts
automating a perl script

Hi,

I have a perl script that takes in 2 numerical values as ARGV[].


Code:
perl script.pl parameter1 num1 num2

in my case I have 1000's of num1 and num2. I can have them in separate files. Please let me know how to automate this run using shell scripting or using awk, so that I don't have to enter all the values.
Sponsored Links
    #2  
Old 08-03-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,400
Thanks: 492
Thanked 2,537 Times in 2,420 Posts
Depending on what these input files look like, it may be as simple as
Code:
cat filename1 filename2 filename3 | xargs -n 2 perl script.pl parameter1

This will accept files of pure numbers separated by spaces and/or newlines.

If that's not what your files look like, please post an example, otherwise we can't help.
Sponsored Links
    #3  
Old 08-09-2012
Registered User
 
Join Date: Oct 2009
Posts: 162
Thanks: 17
Thanked 0 Times in 0 Posts
How do I change the above command when I put the 2 numerical values in one file (separated by tab) ( I have 1000's of values (lines) in that file) and I want to direct the output file (1000 files) using '>'.

example of my tab delimited parameter file is

Code:
38215   41324
41361   41664
41696   42207
42230   42404
42406   42514

    #4  
Old 08-09-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,400
Thanks: 492
Thanked 2,537 Times in 2,420 Posts
If each line needs a separate output file, then:

Code:
OUTPUT=1
while read A B
do
        OUTPUT_FILENAME=`printf "%04d" "$OUTPUT"`
        perl script.pl $A $B > ${OUTPUT_FILENAME}
done < inputfile

If you only want one output file, the code I already gave you will work.
Sponsored Links
    #5  
Old 08-09-2012
balajesuri's Avatar
#! /bin/bash
 
Join Date: Apr 2009
Location: India
Posts: 1,570
Thanks: 15
Thanked 441 Times in 426 Posts
@Lucky Ali: If you're allowed to modify the perl program, you could open the tab delimited parameter file using a file-handle and read its contents inside from inside the program. That way, you wouldn't have to bother about writing a wrapper shell script.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl - automating if statement test Galt Shell Programming and Scripting 3 12-31-2009 10:22 PM
Automating A Perl Script over a database fraizerangus Shell Programming and Scripting 1 10-02-2009 12:26 PM
Help in automating dates in ksh script italia1971luca Shell Programming and Scripting 1 06-04-2008 06:29 AM
cron ? automating a script hassanj UNIX for Dummies Questions & Answers 8 12-22-2007 08:29 AM
automating sftp script Rajeshsu Shell Programming and Scripting 1 07-27-2005 04:06 PM



All times are GMT -4. The time now is 11:57 PM.