Solved

first second third words in a line

Posted on 2004-08-17
2
255 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
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 20

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now