0

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

3
  • This might be helpful. Commented Mar 2, 2020 at 3:08
  • fmt -1 ConfigFile | grep -qxF 'key=value' or grep -q '^key=value$ ConfigFile or grep -qE '^key=value([ \t].*)?$' ConfigFile depending on what you want to happen if you find space/tab Commented Mar 2, 2020 at 4:00
  • @jhnc the above command works for me thank you very much. If possible can you please post it as an answer. Commented Mar 2, 2020 at 5:09

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

The below command worked out for me as suggested by @jhnc

sudo fmt -1 FILEPATH | grep -qxF 'KEY=VALUE'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.