Skip to main content
edited tags
Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
edited tags
Link
Kusalananda
  • 355.7k
  • 42
  • 735
  • 1.1k
added 287 characters in body
Source Link
Melab
  • 4.4k
  • 10
  • 41
  • 59

I'm looking to manipulate the output of $tree --noreport$ in such a way that replaces the leading box-drawing characters and spaces on each line with a matching number of spaces. If I were to write the pattern for matching these characters, it would be ^\\(\u2500\\|\u2514\\|\u251C\\| \\)*\u2500. This string would be wrapped in $'...' because Unicode escape sequences are not recognized by sed. This pattern occurs on every line of the output of tree --noreport except for the first. Each character in each matching string needs to be replaced with a space.

Example input:

.
├── docs
│   ├── jokes
│   │   └── knock_knock.txt
│   └── work
├── images
└── .profile

Example output:

.
    docs
        jokes
            knock_knock.txt
        work
    images
    .profile

The output I'm trying to getnow realizing for my purposes that I need to using this question asremove ambiguity over where a stepping stonefile or folder's name starts (a file or folder's name may begin with one or more spaces), so the output should actually look maybe like:

.
    docs/docs
        /jokes/
            /knock_knock.txt
        work/work
    /images
    /.profile

The \u2500 at the end of my provided pattern actually distinguishes between tree's formatting and the start of the file/folder's name.

I'm looking to manipulate the output of $tree --noreport$ in such a way that replaces the leading box-drawing characters and spaces on each line with a matching number of spaces. If I were to write the pattern for matching these characters, it would be ^\\(\u2500\\|\u2514\\|\u251C\\| \\)*\u2500. This string would be wrapped in $'...' because Unicode escape sequences are not recognized by sed. This pattern occurs on every line of the output of tree --noreport except for the first. Each character in each matching string needs to be replaced with a space.

Example input:

.
├── docs
│   ├── jokes
│   │   └── knock_knock.txt
│   └── work
├── images
└── .profile

Example output:

.
    docs
        jokes
            knock_knock.txt
        work
    images
    .profile

The output I'm trying to get to using this question as a stepping stone:

.
    docs/
        jokes/
            knock_knock.txt
        work/
    images
    .profile

I'm looking to manipulate the output of $tree --noreport$ in such a way that replaces the leading box-drawing characters and spaces on each line with a matching number of spaces. If I were to write the pattern for matching these characters, it would be ^\\(\u2500\\|\u2514\\|\u251C\\| \\)*\u2500. This string would be wrapped in $'...' because Unicode escape sequences are not recognized by sed. This pattern occurs on every line of the output of tree --noreport except for the first. Each character in each matching string needs to be replaced with a space.

Example input:

.
├── docs
│   ├── jokes
│   │   └── knock_knock.txt
│   └── work
├── images
└── .profile

Example output:

.
    docs
        jokes
            knock_knock.txt
        work
    images
    .profile

I'm now realizing for my purposes that I need to remove ambiguity over where a file or folder's name starts (a file or folder's name may begin with one or more spaces), so the output should actually look maybe like:

.
    /docs
        /jokes/
            /knock_knock.txt
        /work
    /images
    /.profile

The \u2500 at the end of my provided pattern actually distinguishes between tree's formatting and the start of the file/folder's name.

added 497 characters in body
Source Link
Melab
  • 4.4k
  • 10
  • 41
  • 59
Loading
Source Link
Melab
  • 4.4k
  • 10
  • 41
  • 59
Loading