帮助使用命令行来提取stdout上的数据片段 [英] help using command line to extract snippets of data on stdout

查看:125
本文介绍了帮助使用命令行来提取stdout上的数据片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要提取以下字符串/数据的选项:

  / work / foo / processed / 25 
/ work / foo / processed / myproxy
/ work / foo / processed / sample

=或=

  25 
myproxy
示例



但是如果我看到这两个会有帮助。



c> cut 或perl或任何其他工作方式:

 找到3项
drwxr-xr-x - foo_hd foo_users 0 2011-03-16 18:46 / work / foo / processed / 25
drwxr-xr-x - foo_hd foo_users 0 2011-04-05 07:10 / work / foo / processed / myproxy
drwxr-x --- - foo_hd testcont 0 2011-04-08 07:19 / work / foo / processed / sample

执行 cut -d-f6 会得到 foo_users testcont 。我尝试将字段增加到更高的值,我只是不能得到我想要的。



我不知道 / code>是有益于这个或像perl的东西?
基本目录将保持静态 / work / foo / processed



第一行找到Xn项已删除。


code><您的命令> | grep -P -o'[\ / \.\w] + $'

如果'/ work / foo / processed'目录总是静态的,那么:

< Your Command> | grep -P -o'\ / work\ / foo\ / processed \ /.+$'

-o:仅显示与PATTERN匹配的匹配线的部分。
-P:将PATTERN解释为Perl正则表达式。

在此示例中,输入中的最后一个字符将匹配。
(字也可以包含点),因此文件名,如'text_file1.txt',可以匹配)。
当然,你可以根据你的要求改变模式。


I would like the option of extracting the following string/data:

/work/foo/processed/25
/work/foo/processed/myproxy
/work/foo/processed/sample

=or=

25
myproxy
sample

But it would help if I see both.

From this output using cut or perl or anything else that would work:

Found 3 items
drwxr-xr-x   - foo_hd foo_users          0 2011-03-16 18:46 /work/foo/processed/25
drwxr-xr-x   - foo_hd foo_users          0 2011-04-05 07:10 /work/foo/processed/myproxy
drwxr-x---   - foo_hd testcont           0 2011-04-08 07:19 /work/foo/processed/sample

Doing a cut -d" " -f6 will get me foo_users, testcont. I tried increasing the field to higher values and I'm just not able to get what I want.

I'm not sure if cut is good for this or something like perl? The base directories will remain static /work/foo/processed.

Also, I need the first line Found Xn items removed. Thanks.

解决方案

Try this out :

<Your Command> | grep -P -o '[\/\.\w]+$' 

OR if the directory '/work/foo/processed' is always static then:

<Your Command>| grep -P -o '\/work\/foo\/processed\/.+$' 

-o : Show only the part of a matching line that matches PATTERN.
-P : Interpret PATTERN as a Perl regular expression.

In this example, the last word in the input will be matched . (The word can also contain dot(s)),so file names like 'text_file1.txt', can be matched). Ofcourse, you can change the pattern, as per your requirement.

这篇关于帮助使用命令行来提取stdout上的数据片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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