Shell script to run a python program on multiple entries in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to run a python program on multiple entries in a file
# 1  
Old 11-11-2010
Shell script to run a python program on multiple entries in a file

Hello

I am trying to run a python program using shell script, which takes a single argument from a file.

This file has one entry per line :
Code:
1aaa
2bbb
3ccc
4ddd
5eee
...
...
...

My shell script runs the program, only for the last entry :

Code:
#!/bin/sh
IFS=$'\n'

for line in $(cat my_filename);
do
        python my_program.py $line > output.file
done

Can someone help me with this?
I need to run this program for all the entries (per line) in my file.

Thanks!
# 2  
Old 11-11-2010
Code:
#!/bin/ksh

\rm -rf output.file
while read line
do
   python my_program.py $line >> output.file
done < my_filename

# 3  
Old 11-11-2010
Thanks so much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python script to run multiple command and append data in output csv file

Experts, I am writing a script and able to write only small piece of code and not able to collect logic to complete this task. In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file Now have to... (0 Replies)
Discussion started by: as7951
0 Replies

2. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

3. Programming

Regarding Python Program with Shell Script

Hi All, I have written a shell script which is using the expect method, it is working fine in terminal window, and then I have executed via python script its also working fine in command prompt functioning properly, I used subprocess.Popen method to execute the shell script file, its working... (0 Replies)
Discussion started by: janaefx
0 Replies

4. Shell Programming and Scripting

Perl program to run a Shell script issues...

Hi all, I have the following Perl script which is intended to run a Shell script and generate some logging for the purposes of tracking weather or not the script ran. I get an error, of course, since I don't know what I'm doing really. Here is the code: #!/opt/perl/bin/perl -w ... (14 Replies)
Discussion started by: zixzix01
14 Replies

5. Shell Programming and Scripting

Shell script to run all the python scripts from particular directory

I have N number of python scripts which i am receiving from REST web server and i am saving them in /home/mandar/ . Now i want to write a script to run all the python scripts from this directory and monitor them every minute...if any process is dead or hung it should be restarted by this script. ... (0 Replies)
Discussion started by: Mandar Nandale
0 Replies

6. UNIX for Dummies Questions & Answers

Using Shell Script To Loop Program Through Multiple Text Files

Hello, So I have approximately 300 files of raw data (.txt) files that I am using to perform statistical analysis. I have been able to construct a Fortran program that is able to perform my statistical analysis on a file by file basis. However, I now want to be able to loop program through... (19 Replies)
Discussion started by: Jimmyd24
19 Replies

7. Shell Programming and Scripting

Run multiple python programs sequentially.

I HAVE WRITTEN NINE PYTHON CODES TO PERFORM A TASK ........ I WISH TO RUN THEM SEQUENTIALLY. eg. code1__code2 >>>>>>>>code9.py TO GET DESIRED OUTPUT. PLS HELP ME WRITTING SHELL SCRIPT .. I HAVE TO DISTRIBUTE THESE CODE FOR BEING USED BY OTHERS. (2 Replies)
Discussion started by: upvan111
2 Replies

8. Shell Programming and Scripting

Run shell script from C program by calling fork and execl

I need to write a c program that uses the fork and excel system calls to run the shell script mode invoked like this: "./mode 644 ls -l" (that is the argumetns will always be 644 ls -l) here's the mode script: #!/bin/sh octal="$1" shift find . -maxdepth 1 -perm $octal -exec $@ {} \; ... (3 Replies)
Discussion started by: computethis
3 Replies

9. Shell Programming and Scripting

problem accessing Multiple Variables from C Program to a Shell script

program name--test #!/bin/bash output1=`/home/user/a.c` output2=`/home/user/a.c` k=`$output1 + 1` m=`$output2 + 1` echo $k echo $m --------------------------------------------------------------------------- prgram name--a.c #include<stdio.h> int main() (1 Reply)
Discussion started by: sameworld1980
1 Replies

10. Shell Programming and Scripting

want to run different files under the same program using shell script

suppose have different files 1.1 2.2 3.3 4.4 5.5 All the files have to run under the same command say tr -d '\n' so how to run all the files under the same command by using shell script (3 Replies)
Discussion started by: cdfd123
3 Replies
Login or Register to Ask a Question