Search code examples
bashparsingawksedgit-diff

git diff, getting just the changed characters


I want to get list of all characters, that were used to change files in directory.

The closest I got to this problem was using:

git diff --color-words="[^[:space:]]|([[:alnum:]]|UTF_8_GUARD)+"
--no-index ./original_directory/ ./changed_directory/

By using this command, I get lines with highlighted characters, which were changed. Is there any way to sed/grep/awk the output, so that output will be just the colored characters?


Solution

  • git diff --color | awk '/^\33\[3[12]m/'
    
    1. Use --color so that colors are passed to Awk

    2. Green lines will begin with the escape sequence \33[32m

    3. Red lines will begin with the escape sequence \33[31m

    Example