nixCraft Linux Forum

nixCraft

Linux / UNIX 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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 31-10-2007, 03:34 AM
AHJ AHJ is offline
Junior Member
User
 
Join Date: Oct 2007
OS: Debian
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
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; 31-10-2007 at 03:41 AM.
Reply With Quote
  #2 (permalink)  
Old 31-10-2007, 06:04 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 246 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
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 Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
/etc/hosts file ricc Linux software 1 08-05-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 07-12-2006 03:51 PM
Log File for AWStats ! honey bee Linux software 1 30-03-2006 09:18 PM
how to do nohup on an sh file Linux software 1 30-01-2006 03:57 PM


All times are GMT +5.5. The time now is 05:21 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 31 32 33 34 35 36 37 38