Technical challenge with AWK

varaprasadkadali

New Member
Joined
Dec 20, 2021
Messages
1
Reaction score
0
Credits
22
HI team ,

as i am new for linux, facing technical challenge with AWK command .
while passing shell variables in AWK command ,AWK is not reading those variable .

ex:

i am having below files and reading User Name ,Host names from text1.txt and finding same similar entries on step1.txt(on column 2,3)

if user name match with 2nd column and host name match with 3rd column of step1.txt then those entries should redirect to another file

cat text1.txt
-------------
NZ_USER=p123
NZ_HOST=server4
NZ_PASSWORD=abc


cat step1.txt
--------------
text1.txt|NZ_USER=p123|NZ_HOST=server4|NZ_PASSWORD=abc
text2.txt|NZ_USER=p123|NZ_HOST=server4|NZ_PASSWORD=abc
text3.txt|NZ_USER=p123|NZ_HOST=server3|NZ_PASSWORD=bvc
text1.txt|NZ_USER=p355|NZ_HOST=server4|NZ_PASSWORD=a1c
text2.txt|NZ_USER=p356|NZ_HOST=server3|NZ_PASSWORD=89c


shell script
--------------

#!/bin/bash

export curruser=`grep NZ_USER text1.txt|cut -d'=' -f 2|sed 's/ //g' | tr "[:lower:]" "[:upper:]"`
export currhost=`grep NZ_HOST text1.txt|cut -d'=' -f 2|sed 's/ //g' | tr "[:lower:]" "[:upper:]"`
awk -v curr_user="$curruser" -v curr_host="$currhost" -F'|' '$2 ~ '/curr_user/' && $3 ~ '/curr_host/' {print $0}' step1.txt >step2.txt


here curr_name,curr_host values are substituting in AWK and getting 0 records

it would be great if you doing help on this issue .

Thanks
Prasad
 

Members online


Latest posts

Top