Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 使用sed和find命令的树功能_Unix_Sed_Tree_Find - Fatal编程技术网

Unix 使用sed和find命令的树功能

Unix 使用sed和find命令的树功能,unix,sed,tree,find,Unix,Sed,Tree,Find,在unix.com上遇到这个命令行,它在unix中充当树命令。 我想找个人解释一下sed命令到底在做什么。 我无法理解语法 现在我知道了基本的sed命令语法。我仍然对unix环境有一些了解 PS:Command工作得很好,讨论在该论坛上结束。find命令只查找目录并打印它们 sed命令如下: find . -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' 让我们一步一步地看看命令的作用: 查找所有目录并打印其名称: sed -e '

在unix.com上遇到这个命令行,它在unix中充当树命令。 我想找个人解释一下sed命令到底在做什么。 我无法理解语法

现在我知道了基本的sed命令语法。我仍然对unix环境有一些了解


PS:Command工作得很好,讨论在该论坛上结束。

find命令只查找目录并打印它们

sed
命令如下:

find . -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
让我们一步一步地看看命令的作用:

查找所有目录并打印其名称:

sed -e 's;[^/]*/;|____;g;s;____|; |;g'
        ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
         |               |
         |               replace ____| with  |
         replace everything up to the last / with ____
将直到最后一个
/
的所有内容替换为
\uuuuuuuu

  • sed-e's;[^/]*/;|____;g'
    的读法如下:
    • [^/]*
      -->获取与
      /
      不同的所有字符(
      *
      )。注意,
      ^
      在这里代表否定
    • /
      -->匹配一个
      /
    • 给定该块,将其替换为字符串
      | uuuuu
请参见一个示例:

$ find . -type d -print 
.
./python
./python/mytest
./python/mytest2
./python/mytest2/bk
./python/mytest2/infiles
./bash
./bash/backup
./awk
./sed
在这种情况下:

$ echo "hello/how/are/you" | sed 's;[^/]*/;;g'
you

$ echo "hello/how/are/you" | sed 's;[^/]*/;|____;g'
|____|____|____you
替换为

$ find . -type d -print | sed -e 's;[^/]*/;|____;g'
.
|____python
|____|____mytest
|____|____mytes2
|____|____|____bk
|____|____|____infiles
|____bash
|____|____backup
|____awk
|____sed
我们通常会看到
sed
表达式,如:

$ find . -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
.
|____python
| |____mytest
| |____mytest2
| | |____bk
| | |____infiles
|____bash
| |____backup
|____awk
|____sed
但是,如果怀疑
/
可能有问题,可以使用不同的分隔符。因此,在本例中,分隔符是

sed 's/hello/bye/g'
最后,请注意:

sed 's;hello;bye;g'
表示两个命令将依次执行,因此相当于:

sed -e 's;[^/]*/;|____;g;s;____|; |;g'
        ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
         1st command     2nd command

find
命令仅查找目录并打印它们

sed
命令如下:

find . -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
让我们一步一步地看看命令的作用:

查找所有目录并打印其名称:

sed -e 's;[^/]*/;|____;g;s;____|; |;g'
        ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
         |               |
         |               replace ____| with  |
         replace everything up to the last / with ____
将直到最后一个
/
的所有内容替换为
\uuuuuuuu

  • sed-e's;[^/]*/;|____;g'
    的读法如下:
    • [^/]*
      -->获取与
      /
      不同的所有字符(
      *
      )。注意,
      ^
      在这里代表否定
    • /
      -->匹配一个
      /
    • 给定该块,将其替换为字符串
      | uuuuu
请参见一个示例:

$ find . -type d -print 
.
./python
./python/mytest
./python/mytest2
./python/mytest2/bk
./python/mytest2/infiles
./bash
./bash/backup
./awk
./sed
在这种情况下:

$ echo "hello/how/are/you" | sed 's;[^/]*/;;g'
you

$ echo "hello/how/are/you" | sed 's;[^/]*/;|____;g'
|____|____|____you
替换为

$ find . -type d -print | sed -e 's;[^/]*/;|____;g'
.
|____python
|____|____mytest
|____|____mytes2
|____|____|____bk
|____|____|____infiles
|____bash
|____|____backup
|____awk
|____sed
我们通常会看到
sed
表达式,如:

$ find . -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
.
|____python
| |____mytest
| |____mytest2
| | |____bk
| | |____infiles
|____bash
| |____backup
|____awk
|____sed
但是,如果怀疑
/
可能有问题,可以使用不同的分隔符。因此,在本例中,分隔符是

sed 's/hello/bye/g'
最后,请注意:

sed 's;hello;bye;g'
表示两个命令将依次执行,因此相当于:

sed -e 's;[^/]*/;|____;g;s;____|; |;g'
        ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
         1st command     2nd command

相关:@fedorqui我知道最终的输出是什么,但我想知道sed命令到底在做什么。我无法理解语法。相关:@fedorqui我理解最终输出是什么,但我想知道sed命令到底在做什么。我不懂语法,谢谢。这就是我一直在找的谢谢你。这就是我要找的