Reputation: 3
I have a configuration file in which I want to check if the the key value pair are present as below and I want them to be a exact match.
key=value xxxxx xxxx
After the key value there can be a space or a tab as shown in the above so I cannot use a simplegrep -q
for getting the key value pair.
Can someone please help me with this
Upvotes: 0
Views: 1253
Reputation: 3
The below command worked out for me as suggested by @jhnc
sudo fmt -1 FILEPATH | grep -qxF 'KEY=VALUE'
Upvotes: 0
Reputation: 7245
Script like this can extract the value
:
awk '/key/ {split($1,a,"=");print a[2]}' input_file
or with variable
KEY="key"
awk -v key=$KEY '$1 ~ key {split($1,a,"=");print a[2]}' input_file
Upvotes: 1