Shell Script help

Hi folks
need some help with a scripts
i need to read a file with 2 values , one label name and other port name

file.txt
R1 2001
R2 2002
R3 2004

and then
open gnome-terminal with command

gnome-terminal --tab -e "telnet locahost 2001" -t "R1" --tab -e "telnet locahost 2002" -t "R2"

can someone guide me how to create a variable that can be passed to gnome-terminal ?

it should read the file , keep adding the hosts to the variable , and then pass the variable to gnome-terminal

thanx all

What about R3 2004 ? Does it deserve a terminal, too?
If not, how will you choose?

"Keep adding"? Is this a growing file?

And: if the file's one thousand lines, you want to open one thousand terminals and do one thousand telnet's, don't you? R U sure?
--
Bye

This will do what you requested.

 
awk 'BEGIN {printf "gnome-terminal"} {printf " --tab -e \"telnet locahost " $2 "\" -t \"" $1 "\"" } END { printf "\n"}' file.txt
 
gnome-terminal --tab -e "telnet locahost 2001" -t "R1" --tab -e "telnet locahost 2002" -t "R2" --tab -e "telnet locahost 2004" -t "R3"

thanx guys for the quick response
now a little refinement please :slight_smile:
create some sort of lock file on first run ,
and on subsequent calls to the same R1 or R2 or R3
kill the first console session and start new

so
if i call the script with
script R1
should work
script R1 R2
should kill the first console sessions and connect again

thanx all