-2

The git command:

git diff-tree --no-commit-id --name-status -r <commit hash>

generates a list that looks kinda like this:

D    path/to/deleted/file.txt
A    path/to/added/file.txt
A    path/to/added/file.asd
M    path/to/modified/file.txt

I want to grep out only the added and modified (A or M) txt files and their paths. I know I can do like this:

grep -v "^D"

to not include the deleted files.

and

grep -o "\w*.txt$"

to only get the txt files. But this command does not give me the path to the files. Since \w only matches the word. Is there any other wildcard that will match until the whitespace character (so that it removes the A/M with corresponding whitespace)?

Felix Rosén
  • 1,391
  • 1
  • 17
  • 33

2 Answers2

1

Use \S to match anything that isn't whitespace.

grep -o '\S*\.txt$'
Barmar
  • 596,455
  • 48
  • 393
  • 495
0
awk /^A/^M/'{$0=$NF} 1'
path/to/added/file.txt
path/to/added/file.asd
path/to/modified/file.txt
$
Digvijay S
  • 2,507
  • 1
  • 6
  • 18