Skip to main content
added explanation
Source Link
manatwork
  • 32.1k
  • 8
  • 104
  • 93

As a first idea, awk:

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

But this decision may depend on the other operations you have to perform.


Explanations as requested 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 essential part is the use of RT (record terminator) built-in variable:

   RT          The record terminator.  Gawk sets RT to the input text that
               matched the character or regular expression specified by
               RS.

As a first idea, awk:

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

But this decision may depend on the other operations you have to perform.

As a first idea, awk:

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

But this decision may depend on the other operations you have to perform.


Explanations as requested 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 essential part is the use of RT (record terminator) built-in variable:

   RT          The record terminator.  Gawk sets RT to the input text that
               matched the character or regular expression specified by
               RS.
Post Undeleted by manatwork
Post Deleted by manatwork
Source Link
manatwork
  • 32.1k
  • 8
  • 104
  • 93

As a first idea, awk:

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

But this decision may depend on the other operations you have to perform.