Solved

first second third words in a line

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
NTP Server in VMware 5 466
UNIX SCP 5 96
Need a version of telnet and/or ssh that supports tcp wrappers on AIX 5.1 16 112
Best way to split and output to csv in bash 2 81
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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

739 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