无法过滤包含&QUOT行,是一个目录"通过SED / AWK [英] Unable to filter rows which contain "Is a directory" by SED/AWK

查看:142
本文介绍了无法过滤包含&QUOT行,是一个目录"通过SED / AWK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行code给我下面的示例数据

I run the code gives me the following sample data

md5deep find * | awk '{ print $1 }'

输出的样本

    /Users/math/Documents/Articles/Number theory: Is a directory
    258fe6853b1bfb2d07f512ff6bec52b1
    /Users/math/Documents/Articles/Probability and statistics: Is a directory
    4811bfb2ad04b9f4318049c01ebb52ef
    8aae4ac3694658cf90005dbdea37b4d5
    258fe6853b1bfb2d07f512ff6bec52b1

我试图过滤包含行是一个目录按SED失败

md5deep find * | awk '{ print $1 }' | sed s/\/*//g

它的示例输出

/Users/math/Documents/Articles/Number theory: Is a directory
/Users/math/Documents/Articles/Topology: Is a directory
/Users/math/Documents/Articles/useful: Is a directory

我怎样才能筛选出其中包含的每一行是个目录由SED / AWK?

[澄清]
我想筛选出包含的是一个目录的行

推荐答案

我没有使用 md5deep 工具,但我相信那些线的错误信息;他们将前往标准误差而不是标准出来,所以他们直接前往你的终端,而不是通过管道。因此,他们不会被你的sed命令过滤。你可以通过你的合并标准错误和标准输出流进行筛选,但

I have not used the md5deep tool, but I believe those lines are error messages; they would be going to standard error instead of standard out, and so they are going directly to your terminal instead of through the pipe. Thus, they won't be filtered by your sed command. You could filter them by merging your standard error and standard output streams, but

它看起来像(我不知道,因为你缺少反引号),你想叫

It looks like (I'm not sure because you are missing the backquotes) you are trying to call

md5deep `find *`

和发现将返回所有的文件和目录。

and find is returning all of the files and directories.

你可能想要做什么的一些注意事项:

Some notes on what you might want to do:


  • 看起来 md5deep 有递归选项-r。所以,你可能会想尝试:

  • It looks like md5deep has a -r for "recursive" option. So, you may want to try:

md5deep -r *

而不是find命令。

instead of the find command.

如果你希望使用找到命令,你可以用它来限制仅文件型的F ,代替文件和目录。此外,你不需要通过 * 成find命令(这可能会混淆找到如果有文件有一个看起来像找到理解)的选项名称;传递将通过当前目录进行递归搜索。

If you do wish to use a find command, you can limit it to only files using -type f, instead of files and directories. Also, you don't need to pass * into a find command (which may confuse find if there are files that have names that looks like the options that find understands); passing in . will search recursively through the current directory.

find . -type f


  • SED 如果你想在你的模式来使用斜杠,它可以是一个痛苦与\\正确引用它们。您也可以选择一个不同的角色来界定你的正常前pression; SED 取值命令作为分隔符将使用后的第一个字符。你的模式也缺少 。在常规的前pressions,以表明您使用任意字符的一个实例。,并表示零个或更多的preceding前pression的你用 * ,所以。* 表示零个或多个任意字符(这是从glob模式不同,其中 * 单独表示零个或多个任意字符)。

  • In sed if you wish to use slashes in your pattern, it can be a pain to quote them correctly with \. You can instead choose a different character to delimit your regular expression; sed will use the first character after the s command as a delimiter. Your pattern is also lacking a .; in regular expressions, to indicate one instance of any character you use ., and to indicate "zero or more of the preceding expression" you use *, so .* indicates "zero or more of any character" (this is different from glob patterns, in which * alone means "zero or more of any character").

    sed "s|/.*||g"
    


  • 如果你真的想成为包括在标准输出的标准错误流,所以它会通过管道,那么你可以运行:

  • If you really do want to be including your standard error stream in your standard output, so it will pass through the pipe, then you can run:

    md5deep `find *` 2>&1 | awk ...
    


  • 如果你只是想忽略错误,都可以重定向到的/ dev / null的,这是一个特殊的文件,只是丢弃任何进入它

  • If you just want to ignore stderr, you can redirect that to /dev/null, which is a special file that just discards anything that goes into it:

    md5deep `find *` 2>/dev/null | awk ...
    


  • 综上所述,笔者认为下面的命令将帮助您立即解决问题,和上面列出的其他建议可以帮助你,如果我不undersand什么你要找的:

    In summary, I think the command below will help you with your immediate problem, and the other suggestions listed above may help you if I did not undersand what you were looking for:

    md5deep -r * | awk '{ print $1 }'
    

    这篇关于无法过滤包含&QUOT行,是一个目录"通过SED / AWK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆