Multple multi-line regex matches in Bash -
I am trying to parse some simple strings in the Bash script. Basically, I have a file that contains multiple multi-line fields, each field is surrounded by a known header and footer.
I want to extract each field in an array or similar, like
& gt; FILE = 'cat file `& gt; REGEX = "@ # @ # @ # [\ S \ S] +? @ # @ # @" & Gt; & Gt; If [[$ FILE = ~ $ REGEX]] then & gt; Now $ BASH_REMATCH & gt; Fi
file:
@ # @ # @ ##################### ############# This area is a @ @ # @ # @ # @ # @ # @ # # # # ################# ############### This area is two, they can be any number of rows @ # @ # @ #
now complete me The problem is that with Bash "news" "."
, I can match it to "pcregrep-M", but it is definitely going to match the whole file.
If you have
awk 'BEGIN {RS = "@ # * #"} NF {gsub} ("\ N", "") # Remove is that you want to print new lines "- & gt;" $ 0 # Array ARR [+++] = $ 0} 'file
output
$ /shell.sh - & gt; This field is one - & gt; This area is two, they can be any number of rows
Comments
Post a Comment