1

I've tried something like this

tree -C | fzf --ansi | awk -F'|' '{print $NF}'
├── repo.git/
│   ├── folder/
│   │   ├── subfolder/
│   │   │   ├── output.0
│   │   │   └── traces.1
│   │   ├── subfolder/
│   │   │   └── fold/
│   │   │       └── subtree/
│   │   │           ├── .gitignore
│   │   │           ├── stamp-h1 item
│   │   │           └── stamp-h2

I want to grab stamp-h1 item, in other words the filename

1 Answer 1

1

If you really have to use tree then you should use tree -CQ where Q quotes the filenames with double quotes.
So the tree output would become:

└── "repo.git"
    └── "folder"
        ├── "subfolder"
        │   ├── "output.0"
        │   └── "traces.1"
        └── "subfolder2"
            └── "fold"
                └── "subtree"
                    ├── "stamp-h1 item"
                    └── "stamp-h2"

And for getting the filenames you can apply a regular expression using sed for getting only the values between " ". So your code should be like this:

tree -CQ | fzf --ansi | sed 's/.*\"\(.*\)\"/\1/g'

With the code above if you select repo.git you will obtain:

repo.git

If you select "stamp-h1 item" you will obtain:

stamp-h1 item

Or if you want to print the value between " you should use:

tree -CQ | fzf --ansi | sed 's/.*\"\(.*\)\"/"\1"/g'
#Example output:
"stamp-h1 item"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .