Home > Mobile >  How to use this regex with grep in shell script?
How to use this regex with grep in shell script?

Time:12-09

I need to extract the public key in the shell script, Not sure how to use this. I am new to shell script. https://regex101.com/r/SXDEaU/1

Content of the file:

public_key=#STARTKEY#<public key base64 encoded>#ENDKEY#

Regex: /public_key=#STARTKEY#(.*)#ENDKEY#/s

Since the key is base64 encoded, it is a multiline string.

Desired output: <public key base64 encoded>

CodePudding user response:

perl -M5.010 -0777ne'say for /public_key=#STARTKEY#(.*)#ENDKEY#/s' file

CodePudding user response:

With awk using its RS variable and setting it to paragraph mode please try following code.

awk -v RS= 'match($0,/public_key=#STARTKEY#.*#ENDKEY#/){print substr($0,RSTART 21,RLENGTH-29)}'  Input_file
  • Related