Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grep -G '#.*' file
- text
- text
- #comment
- changed text
- #comment
- $ # comparing files with comment-only changes
- $ diff -u -I '#.*' test{1,2}
- $ # comparing files with both comment and regular changes
- $ diff -u -I '#.*' test{2,3}
- --- test2 2011-07-20 16:38:59.717701430 +0200
- +++ test3 2011-07-20 16:39:10.187701435 +0200
- @@ -1,2 +1,2 @@
- -text
- +changed text
- #comment
- diff -u -B <(grep -vE '^s*(#|$)' test1) <(grep -vE '^s*(#|$)' test2)
- diff -b -I '^#' -I '^ #' file1 file2
- diff -u -B <(sed 's/^[[:blank:]]*#.*$/ /' file1) <(sed 's/^[[:blank:]]*#.*$/ /' file2)
- File test1:
- text
- #comment
- other text
- File test2:
- text
- new line here
- #comment changed
- other text changed
- $ echo -e "#!/usr/bin/sed -fns/^[[:blank:]]*#.*$/ /" > outcom.sed
- $ echo "diff -u -B <(./outcom.sed $1) <(./outcom.sed $2)" > mydiff.sh
- $ chmod +x mydiff.sh outcom.sed
- $ ./mydiff.sh file1 file2 > file.dif
- $ cat file.dif
- --- /dev/fd/63 2014-08-23 10:05:08.000000000 +0200
- +++ /dev/fd/62 2014-08-23 10:05:08.000000000 +0200
- @@ -1,2 +1,3 @@
- text
- +new line
- -other text
- +other text changed
- $ patch -p0 file1 < file.dif
- patching file file1
- Hunk #1 FAILED at 1.
- 1 out of 1 hunk FAILED -- saving rejects to file file1.rej
- $ echo "diff -B <(./outcom.sed $1) <(./outcom.sed $2)" > mydiff.sh
- $ ./mydiff.sh file1 file2 > file.dif
- $ cat file.dif
- 1a2
- > new line
- 3c4
- < other text
- ---
- > other text changed
- $ patch -p0 file1 < file.dif
- patching file file1
- $ cat file1
- text
- new line
- #comment
- other text changed
- egrep -v "^$|^[[:space:]]*#" /path/to/file
- sed -e '/^#.*/d' -e 's/#.*//g' | cat -s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement