Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get names of root directories in an array in bash

I have a list of files which are stored here:

FILES_CHANGE=(git diff --name-only --cached)

This retrieves for example:

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

home
test

How can I do this with bash? Any possibility to single line it with sed?

>Solution :

Another option using :

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
$
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading