1755730 Members
3957 Online
108837 Solutions
New Discussion юеВ

Question for Ramesh ..

 
SOLVED
Go to solution
someone_4
Honored Contributor

Question for Ramesh ..

Alright Ramesh
last night . well should I say late last night you gave a response to a shell script question

cat $in_file | while read COL1 COL2
do
command -a $COL1 -b $COL2
done

Now my question is can you give me an example of what this output will look like or how I would use this in a script??

Richard

3 REPLIES 3
Patrick Wallek
Honored Contributor
Solution

Re: Question for Ramesh ..

The output from that will depend greatly on what command is run. Who knows what the output will look like.

The person asking the question asked how to read in two strings each line in a file where each line had 2 values and then pass those values to a command. There were no details given as to what command he wanted to run.

You could do this for any command that you pass parameters to.

File to read:

-ld /dir
-la /dir2

cat $infile | while read COL1 COL2
do
ls $COL1 $COL2
done

That would then do an 'ls -ld /dir' and an 'ls -la /dir2'

Make sense?
linuxfan
Honored Contributor

Re: Question for Ramesh ..

Hi Richard,


You can use this in various ways,

Simple eg:
Lets say you want to get the LVname and LV extents in a physical disk

pvdisplay -v /dev/dsk/c0t1d0 | awk '{print $1,$2}' |grep "/dev/" | while read LVNAME LVEXT

Now this gives the name of the LV and the LE of the LV on this disk,

another example
cat /etc/hosts | grep -v "^#" | while read IPADDR HOSTNAME ALIAS
do
echo "$IPADDR:$HOSTNAME:$ALIAS"
done

(This prints the your host table entries seperated by colon, and you can now do whatever you want with each of these variables in your script).

Another example,
ioscan -kfnC disk |grep dev |while read DISK RDISK

Does that answer your question?

-Ramesh
They think they know but don't. At least I know I don't know - Socrates
someone_4
Honored Contributor

Re: Question for Ramesh ..

Thats good stuff .. I like it !

What cleared it up was patricks example
and your /etc/hosts example.

Thanks,
Richard