Issue
I have a list of files which are stored here:
FILES_CHANGE=(git diff --name-only --cached)
test.txt
home/a/c/test.sh
test/s.cpp
I need to get only the occurrencies with root directory name. In the example above would be:
home
test
How can I do this with bash? Any possibility to single line it with sed
?
Solution
Another option using cut:
git diff --name-only | cut -d '/' -f1
Local example:
$ git --no-pager diff --name-only
src/API/Api.php
src/Commands/Data/Data.php
$
$
$ git diff --name-only | cut -d '/' -f1
src
src
$
Answered By - 0stone0 Answer Checked By - Marie Seifert (WPSolving Admin)