帮助使用命令行来提取stdout上的数据片段 [英] help using command line to extract snippets of data on 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屋!