I need to figure out a regular expression to delete all lines that do not begin with either "+" or "-".
I want to print a paper copy of a large diff file, but it shows 5 or so lines before and after the actual diff.
I need to figure out a regular expression to delete all lines that do not begin with either "+" or "-".
I want to print a paper copy of a large diff file, but it shows 5 or so lines before and after the actual diff.
diff -u <some args here> | grep '^[+-]'
Or you could just not produce the extra lines at all:
diff --unified=0 <some args>
In VIM:
:g!/^[+-]/d
Here is the English translation:
g
lobally do something to all lines that do NOT!
match the regular expression: start of line^
followed by either +
or -
, and that something to do is to d
elete those lines.
egrep "^[+-]" difffile >outputfile
Instead of deleting everything that doesn't match you show only lines that match. :)
If you need to do something more complex in terms of regular expressions, you should use this site: http://txt2re.com/
it also provides code examples for many different languages.