read two different variables

General support questions
Post Reply
knzzz
Posts: 137
Joined: 2017/02/25 12:41:42

read two different variables

Post by knzzz » 2019/10/27 16:28:26

Hi Team,

I want to read the server list one by one from file1.txt and install the certain rpm in certain serves list in file 2.txt from top to bottom using the shell script

For eg:
file1.txt
server 1
server2
server3


File2.txt
abc.rpm
def.rpm
ghi.rpm
jkl.rpm

abc .rpm in server1
def.rpm in server 2
ghi.rpm in server 3

Regards
Kanna

aks
Posts: 2958
Joined: 2014/09/20 11:22:14

Re: read two different varaibles

Post by aks » 2019/10/27 18:07:48

Why not (for the general case):

while read LINE
do
case "${LINE}" in
....matches...
*) <- the "not match case".
esac
done < FILE

If you need to trim inputs you can manipulate the LINE variable in the normal way(s).
Also the quoting is important.

aks
Posts: 2958
Joined: 2014/09/20 11:22:14

Re: read two different varaibles

Post by aks » 2019/10/31 19:49:05

(After a private PM):

Okay a bit more subtle that your original post suggested.
Why not just use paste?

$ cat file1.txt
server1
server2
server3
server4

$ cat file2.txt
abc.rpm
def.rpm
ghi.rpm
jkl.rpm

$ paste -d' ' file1.txt file2.txt
server 1 abc.rpm
server2 def.rpm
server3 ghi.rpm
server4 jkl.rpm

$ paste -d' ' file1.txt file2.txt > file3.txt
$ cat file3.txt
server 1 abc.rpm
server2 def.rpm
server3 ghi.rpm
server4 jkl.rpm

(the -d is the delimiter, in our case a space, but by default is a tab).

Post Reply

Return to “CentOS 7 - General Support”