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控制台:如何删除包含在其他行中的行_Unix_Console_Command Line Tool - Fatal编程技术网

unix控制台:如何删除包含在其他行中的行

unix控制台:如何删除包含在其他行中的行,unix,console,command-line-tool,Unix,Console,Command Line Tool,我有一个包含排序路径的文本文件,例如 /abc /abc/def /abc/jkl /def /def/jkl /def/jkl/yui /def/xsd /zde 现在,我想删除包含在其他行中的行。在本例中,应保留以下行: /abc/def /abc/jkl /def/jkl/yui /def/xsd /zde 使用awk和(反向连接和打印文件): 以下是更具可读性的awk版本: { if (substr(prev, 1, length($0)) != $0) # Compare

我有一个包含排序路径的文本文件,例如

/abc
/abc/def
/abc/jkl
/def
/def/jkl
/def/jkl/yui
/def/xsd
/zde
现在,我想删除包含在其他行中的行。在本例中,应保留以下行:

/abc/def
/abc/jkl
/def/jkl/yui
/def/xsd
/zde

使用
awk
和(反向连接和打印文件):

以下是更具可读性的awk版本:

{
    if (substr(prev, 1, length($0)) != $0)  # Compare with last line (substring?)
        print $0;
    prev = $0  # Remember the last line
}
{
    if (substr(prev, 1, length($0)) != $0)  # Compare with last line (substring?)
        print $0;
    prev = $0  # Remember the last line
}