Code for parsing a key/value in in file from shell script

前端 未结 6 1877
心在旅途
心在旅途 2020-11-30 06:44

I have a file that I need to look up a value by key using a shell script. The file looks like:

HereIsAKey This is the value

How can I do so

6条回答
  •  再見小時候
    2020-11-30 07:22

    If you don't have a grep that supports Perl-compatible regular expressions, the following seems to work:

    VAR=$(grep "^$KEY " file | cut -d' ' -f2-)
    

提交回复
热议问题