Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. grep -G '#.*' file
  2.  
  3. text
  4.  
  5. text
  6. #comment
  7.  
  8. changed text
  9. #comment
  10.  
  11. $ # comparing files with comment-only changes
  12. $ diff -u -I '#.*' test{1,2}
  13. $ # comparing files with both comment and regular changes
  14. $ diff -u -I '#.*' test{2,3}
  15. --- test2 2011-07-20 16:38:59.717701430 +0200
  16. +++ test3 2011-07-20 16:39:10.187701435 +0200
  17. @@ -1,2 +1,2 @@
  18. -text
  19. +changed text
  20. #comment
  21.  
  22. diff -u -B <(grep -vE '^s*(#|$)' test1) <(grep -vE '^s*(#|$)' test2)
  23.  
  24. diff -b -I '^#' -I '^ #' file1 file2
  25.  
  26. diff -u -B <(sed 's/^[[:blank:]]*#.*$/ /' file1) <(sed 's/^[[:blank:]]*#.*$/ /' file2)
  27.  
  28. File test1:
  29. text
  30. #comment
  31. other text
  32. File test2:
  33. text
  34. new line here
  35. #comment changed
  36. other text changed
  37.  
  38. $ echo -e "#!/usr/bin/sed -fns/^[[:blank:]]*#.*$/ /" > outcom.sed
  39. $ echo "diff -u -B <(./outcom.sed $1) <(./outcom.sed $2)" > mydiff.sh
  40. $ chmod +x mydiff.sh outcom.sed
  41. $ ./mydiff.sh file1 file2 > file.dif
  42. $ cat file.dif
  43. --- /dev/fd/63 2014-08-23 10:05:08.000000000 +0200
  44. +++ /dev/fd/62 2014-08-23 10:05:08.000000000 +0200
  45. @@ -1,2 +1,3 @@
  46. text
  47. +new line
  48.  
  49. -other text
  50. +other text changed
  51.  
  52. $ patch -p0 file1 < file.dif
  53. patching file file1
  54. Hunk #1 FAILED at 1.
  55. 1 out of 1 hunk FAILED -- saving rejects to file file1.rej
  56.  
  57. $ echo "diff -B <(./outcom.sed $1) <(./outcom.sed $2)" > mydiff.sh
  58. $ ./mydiff.sh file1 file2 > file.dif
  59. $ cat file.dif
  60. 1a2
  61. > new line
  62. 3c4
  63. < other text
  64. ---
  65. > other text changed
  66. $ patch -p0 file1 < file.dif
  67. patching file file1
  68. $ cat file1
  69. text
  70. new line
  71. #comment
  72. other text changed
  73.  
  74. egrep -v "^$|^[[:space:]]*#" /path/to/file
  75.  
  76. sed -e '/^#.*/d' -e 's/#.*//g' | cat -s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement