Created
April 18, 2021 22:35
-
-
Save moriakijp/5db4bef6fb028a11493791abd60ca688 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jq ' | |
| def parsePathname: | |
| split("\\") | {path: .[0:length-1], file: .[-1]}; | |
| # skip over lines that only specify directories | |
| def pathnames: | |
| foreach inputs as $x (null; | |
| if . == null | |
| then if ($x|length) == 0 then 0 else . end | |
| else .+1 | |
| end; | |
| select(. and . > 0)|$x) | |
| | parsePathname ; | |
| reduce pathnames as $pn ({}; | |
| getpath($pn.path + ["children"]) as $children | |
| | setpath($pn.path + ["children"]; $children + [$pn.file]) ); | |
| . | pathnames' | |
| dir.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment