简体   繁体   中英

How to use bash tree command on a text file with directory listing

I have a text file with the directory listing of some folders like

./boost/1.75.0_2/.brew/boost.rb
./boost/1.75.0_2/include/boost/accumulators/accumulators.hpp
./boost/1.75.0_2/include/boost/accumulators/accumulators_fwd.hpp
./boost/1.75.0_2/include/boost/accumulators/statistics.hpp
./boost/1.75.0_2/include/boost/container/node_allocator.hpp
./boost/1.75.0_2/include/boost/container/node_handle.hpp
./boost/1.75.0_2/include/boost/container/options.hpp

and I would like to use the tree command to obtain the following output with the directory structure:

└── 1.75.0_2
    ├── INSTALL_RECEIPT.json
    ├── README.md
    ├── include
    │   └── boost
    │       ├── accumulators
    │       │   ├── accumulators.hpp
    │       │   ├── accumulators_fwd.hpp
    │       │   ├── framework
    │       │   │   ├── accumulator_base.hpp
    │       │   │   ├── accumulator_concept.hpp
    │       │   │   ├── accumulator_set.hpp
    │       │   │   ├── accumulators
    │       │   │   ├── depends_on.hpp
    │       │   │   ├── external.hpp
    │       │   │   ├── extractor.hpp
    │       │   │   ├── features.hpp
    │       │   │   └── parameters
    │       │   ├── numeric
    │       │   │   ├── detail
    │       │   │   ├── functional
    │       │   │   ├── functional.hpp

I cannot access the file system, I only have the text file with directory listing. Is it possibile to use tree on that file?

As a quick hack, you could recreate the actual file structure (can be done anywhere; in /tmp , in a VM, or even on a remote machine) and then run tree :

mkdir tmptree
cd tmptree
sed 's/./\\&/g' yourFile | xargs mkdir -p
tree
cd ..
rm -r tmptree

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM