nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Read arguments from a file and pass them to binary file

This is a discussion on Read arguments from a file and pass them to binary file within the Shell scripting forums, part of the Development/Scripting category; Hello all, I have a pretty simple script to write, but have never done this before and am having problems. ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 10-31-2007, 03:34 AM
AHJ AHJ is offline
Junior Member
User
 
Join Date: Oct 2007
My distro: Debian
Posts: 1
AHJ is on a distinguished road
Default Read arguments from a file and pass them to binary file

Hello all,
I have a pretty simple script to write, but have never done this before and am having problems. Hope someone will help!

I have a text file that looks like this:
0.001 0.002738613 0.997834325
0.002 0.005477226 0.995668666
0.003 0.008215838 0.993503042
0.004 0.010954451 0.991337467
etc

Each of these values is a parameter that I have to input into a program and get results, i.e.

!/bin/csh
AlphaSim -nx 10 -ny 10 -nz 10 -dx 1 -dy 1 -dz 1 -power -ax 2 -ay 2 -az 2 -zsep {0.001} -rmm {0.002738613} -pthr {0.997834325} -iter 1000 -out power_2x2x2_zsep00{it}.txt

so i need this to run for every row in my text file i.e. i need to input three variables from my text file, pass them as parameters to my program, and iterate until end of text file. I'm having such problems, can anyone help?
Thanks!

Last edited by AHJ; 10-31-2007 at 03:41 AM.
Reply With Quote
  #2 (permalink)  
Old 10-31-2007, 06:04 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 838
nixcraft is an unknown quantity at this point
Default

I don't have csh, script but you can write something as follows using bash shell:
Code:
#!/bin/bash
INPUT=file.txt
count=0
exec 3<&0
exec 0<$INPUT
while read line
do
    input1=$(echo $line | awk '{ print $1}')
    input2=$(echo $line | awk '{ print $2}')
    input3=$(echo $line | awk '{ print $3}')
       AlphaSim -nx 10 -ny 10 -nz 10 -dx 1 -dy 1 -dz 1 -power -ax 2 -ay 2 -az 2 -zsep ${input1} -rmm ${input2} -pthr ${input3} -iter 1000 -out power_2x2x2_zsep00${count}.txt
        count=$( expr $count + 1 )
done
exec 0<&3
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
/etc/hosts file ricc Linux software 1 05-08-2007 07:32 PM
How to install .deb file raj Getting started tutorials 0 05-05-2007 12:57 AM
convert pdf (ppt file) into wordppt file sureshbup Linux software 1 12-07-2006 03:51 PM
Log File for AWStats ! honey bee Linux software 1 03-30-2006 09:18 PM
how to do nohup on an sh file Linux software 1 01-30-2006 03:57 PM


All times are GMT +5.5. The time now is 12:49 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30