Extract marked strings from text file using Bash

I have documents which are of the adhering to design - these are parametrised arrangement submits ; the values within the #characters are changed with actual values from a data source relying on setting.

ABC=#PARAMETER_1#:#PARAMETER_2#
SOMETHING_ELSE=#PARAMETER_1#
SOMETHING_NEW=#PARAMETER_2##PARAMETER_3#

I would love to extract from these documents the values in between the hash/pound (#) personalities, to make sure that I can conveniently recognize the parameters called for. There is no typical column size or anything like that, the only criterion being that anything in between 2 # personalities is changed with a value from the data source.

This is the excellent cleansed, deduped result:

PARAMETER_1
PARAMETER_2
PARAMETER_3

I have actually seen this inquiry, yet the critical distinction is that there can be any kind of variety of variables on a certain line in my scenario.

I have actually marked this inquiry with Bash, yet it does not need to be, maybe perl etc, it simply requires to range from the command line in Unix.

1
2022-06-07 14:36:23
Source Share
Answers: 1

As a first suggestion, awk:

awk -vRS='#[^#]+#' 'RT{gsub(/#/,"",RT);p[RT]=1}END{for(i in p)print i}' the_file

But this choice might rely on the various other procedures you need to execute.


Descriptions as asked for in comment.

awk -vRS='#[^#]+#' '   # use /#[^#]+#/ as record separator
RT {   # record terminator not empty?
  gsub(/#/,"",RT)    # remove the # parameter delimiter markup
  p[RT]=1   # store it as key in array p
}
END {   # end of input?
  for (i in p) print i   # loop through array p and print each key
}' the_file

The crucial part is making use of RT (document terminator) constructed - in variable:

   RT          The record terminator.  Gawk sets RT to the input text that
               matched the character or regular expression specified by
               RS.
5
2022-06-07 14:59:50
Source