Solved

first second third words in a line

Posted on 2004-08-17
2
262 Views
Last Modified: 2010-04-21
Hi -

I have a file params.txt which looks like
a   b   c
d   e   f
g   h   i
j    k   l

etc.  , with 3 words per line.

I want to run the programme prog multiple times in a unix loop so that it runs
prog -option1 a -option2 b -option3 c
prog -option1 d -option2 e -option3 f  

etc.

Please tell me an easy way of writing this loop (if there is one).

0
Comment
Question by:glebspy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 11818743
Hi glebspy,

#!/bin/sh

cat param.txt | while read line
do
           arg1=`echo $line | awk ' { print $1 } ' `
           arg2=`echo $line | awk ' { print $2 } ' `
           arg3=`echo $line | awk ' { print $3 } ' `
           prog -option1 $arg1 -option2 $arg2 -option3 $arg3
done

Sunnycoder
0
 
LVL 21

Expert Comment

by:tfewster
ID: 11822443
Sunnycoder, why do it the hard way? What's wrong with:

while read arg1 arg2 arg3
do
  prog -option1 $arg1 -option2 $arg2 -option3 $arg3
done < params.txt

(Of course, if one of the lines has more than 3 entries, arg3 will be everything up to the end of the line...)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question