regex - Use sed to match end of line NOT preceded immediately by a certain character -
i have set of lines followed '\' want print line not containing '\' character @ end of line. note xx# yy# change per file , re-usable, want script print lines match1 '\' end of line.
match1 xx1 xx1 xx1 xx1 \ yy1 yy1 yy1 yy1 \ zz\<1\> zz1 zz1 zz1 xx2 xx2 xx2 xx2 \ ...
output should be:
match1 xx1 xx1 xx1 xx1 \ yy1 yy1 yy1 yy1 \ zz\<1\> zz1 zz1 zz1
my best effort came with:
sed -n '/match1/,/\\/p' file
but not work. or suggestions appreciated.
the following command want:
sed -n '/match1/,/[^\\]$/p' file
using ^
@ start of character class negates match.
following glenn jackman's great comment above solution has little problem. since [^\\]
requires @ least 1 character not work if first line not ends \ empty line. let me add solution should preferred one:
sed -n '/match1/,/\(^\|[^\\]\)$/p' file
Comments
Post a Comment