I found this question and it solved 99% of my issue but I can't figure out to match the end pattern with ^
.
sed - Print lines matched by a pattern range if one line matches a condition
Here are my data, it requires me matching the closing bracket at beginning of the line.
(
Device=B
Data=asdfasdf(qwfw)
Lorem=Ipsum
)
(
Device=A
Data=asdfasdf(aewf)
Lorem=Ipsum
)
(
Device=B
Data=asdfasdf(wef)
)
(
Device=A
Data=asdfasdf(jalks)
)
(
Device=B
Data=asdfasdf(asf)
)
(
Device=C
Data=asdfasdf(asfew)
Lorem=Ipsum
)
I'm trying this command, but it fails to match anything.
sed -n '/(/{:a;N;/^)/!ba;/Device=A/p}' file
If I remove ^
, it returns this
-> % sed -n '/(/{:a;N;/)/!ba;/Device=A/p}' test
(
Device=A
Data=asdfasdf(aewf)
(
Device=A
Data=asdfasdf(jalks)
Does anyone know what am I missing here?
sed version
sed (GNU sed) 4.5
Copyright (C) 2018 Free Software Foundation, Inc.