Hi All
I have a file type such as
[TEST]
client=SSH
server=testing
user=abc
password=xyz
dir=home
[Run]
client=putty
server=running
user=pqr
password=sas
dir=main
[dump]
client=nothing
server=down
user=aaa
password=bbb
dir=lost
I should pass the two value two the script and it should give the result
example ./script Run user
It should give result pqr
Yoda
2
Using Klashxx command:-
#!/bin/ksh
param_1=$1
param_2=$2
cat input.txt | egrep -v "^#" | awk -v tag=$param_1 -v field=$param_2 'match($0, tag){t=1};match($0, field) && t{print $2;exit}' FS="="
An awk parser:
awk -v tag="Run" -v field="user" 'match($0, tag){t=1};match($0, field) && t{print $2;exit}' FS="=" infile
Just look for the complete string:
awk -v tag="Run" -v field="user" 'match($0, tag){t=1;next};$1 == field && t{print $2;exit};/^\[/ && t {print "Not found";exit}' FS="=" infile
With some assumptions:
#!/usr/bin/ksh
awk -F'\n|=' '$1==label{
for(i=2;i<=NF;i+=2)
if($i==attrib)
print $(i+1)
}' label="[$1]" attrib="$2" RS= file
awk -F'[]=[]' '$2==t{p=1} p && $1==f{print $2; exit}' t=Run f=user infile