Append has prefix in while loop

I was using below script to grep one file. I need to append the output using prefix

Data of all-Vms-1.txt

server-1 frame-1 LUN001
server-2 frame-1 LUN002

Data of all-vm-unix.txt

server-1     24
server-2     50

Script used

while read -r g h ;
do
cat all-Vms-1.txt |grep -i $g |awk '$0="frame "$0'|sed -e "s/frame/${g} ${h}/" >> all-vm-unix-with-vc-2

done < all-vm-unix.txt

I need output like this

server-1 24 server-1 frame-1 LUN001
server-2 50 server-2 frame-1 LUN002

But Now it was echo in next line

server-1 24 
server-1 frame-1 LUN001
server-2 50 
server-2 frame-1 LUN002

the usual approach:

awk 'FNR==NR {f1[$1]=$0;next} $1 in f1 {print $0, f1[$1]}' all-Vms-1.txt all-vm-unix.txt

Hi vgersh99

I think it was checking case sensitive and ignore if it dont match. How to ignore case sensitive

Use the tolower(str) function to changes strings to lowercase where appropriate to make it case insensitive...

Sorry where i need to use this code

To adjust vgersh99's suggestion try:

awk '{i=tolower($1)} FNR==NR {f1[i]=$0;next} i in f1 {print $0, f1[i]}' all-Vms-1.txt all-vm-unix.txt
1 Like