由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - 怎样打印出grep后的部分内容?
相关主题
请帮忙看看这个问题a question about renaming.
How do i get a list of all computers?如何把一个目录下的文件名全部改成小写?
vi 一问.[转载] How to list the files with specific permission?
error in my function "write_log"shell programming problems
How to use sed to add newline character?replace a string in all files under a directory?
about vi.How to find a file in the deep children directory?
paste command 里面的 -Re: 如何用grep查找子目录下的文件?--stop!
SOSSSS! Passwd file brokenRe: 如何用grep查找子目录下的文件?
相关话题的讨论汇总
话题: name话题: user话题: awk话题: grep话题: use
进入Unix版参与讨论
1 (共1页)
t*******l
发帖数: 421
1
for example,
1.grep "User Name:" user.txt
User Name: John
User Name: Mary
User Name: Michael
现在我想只打印出冒号后面的名字,并使之间隔显示在同一行里.怎么实现?
thanks.
D**e
发帖数: 10169
2
grep "User Name:" user.txt | awk -F "\:" '{print $2}' | tr '\n' ' '

【在 t*******l 的大作中提到】
: for example,
: 1.grep "User Name:" user.txt
: User Name: John
: User Name: Mary
: User Name: Michael
: 现在我想只打印出冒号后面的名字,并使之间隔显示在同一行里.怎么实现?
: thanks.

t*******l
发帖数: 421
3
doesn't work :))

【在 D**e 的大作中提到】
: grep "User Name:" user.txt | awk -F "\:" '{print $2}' | tr '\n' ' '
s**s
发帖数: 242
4
no space after -F, and no need to use tr

【在 t*******l 的大作中提到】
: doesn't work :))
t*******l
发帖数: 421
5
this time it works, but nothing came out....

【在 s**s 的大作中提到】
: no space after -F, and no need to use tr
D**e
发帖数: 10169
6
what's the matter?

【在 t*******l 的大作中提到】
: doesn't work :))
t*******l
发帖数: 421
7
awk: syntax error near line 1
awk: bailing out near line 1

【在 D**e 的大作中提到】
: what's the matter?
D**e
发帖数: 10169
8
how do you chop off the newline without tr?

【在 s**s 的大作中提到】
: no space after -F, and no need to use tr
D**e
发帖数: 10169
9
leave spaces where appropriate.

【在 t*******l 的大作中提到】
: awk: syntax error near line 1
: awk: bailing out near line 1

c*****z
发帖数: 1211
10
grep xxx |awk -F":" '{printf("%s ",$2);}'
the ' is the one next to L, the same key of "

【在 t*******l 的大作中提到】
: awk: syntax error near line 1
: awk: bailing out near line 1

c*****t
发帖数: 1879
11
so many awk fans. Sigh, I don't know awk, but other common commands
work well too.
echo `grep xxx | cut -d: -f2`
Of course, it runs two instead of one, but I would assume that the
bottleneck was the grep part...
c*****z
发帖数: 1211
12
cut is ok here, but awk is more powerful and can handle more complicated cas
es.
as to master a unix cmd tools is really not easy, to know how to use awk is
a better idea for me :)
anyway, gawk is available on almost all unix platform ( and i'm using gawk )

【在 c*****t 的大作中提到】
: so many awk fans. Sigh, I don't know awk, but other common commands
: work well too.
: echo `grep xxx | cut -d: -f2`
: Of course, it runs two instead of one, but I would assume that the
: bottleneck was the grep part...

t*******l
发帖数: 421
13
how to use it?:)

【在 c*****z 的大作中提到】
: cut is ok here, but awk is more powerful and can handle more complicated cas
: es.
: as to master a unix cmd tools is really not easy, to know how to use awk is
: a better idea for me :)
: anyway, gawk is available on almost all unix platform ( and i'm using gawk )

w*****n
发帖数: 94
14
use Perl, it can do anything that sed/awk or shell can do and many more.
perl -nle '/xxx/ && /:\s*(\w+)/ && print $1'

【在 c*****z 的大作中提到】
: cut is ok here, but awk is more powerful and can handle more complicated cas
: es.
: as to master a unix cmd tools is really not easy, to know how to use awk is
: a better idea for me :)
: anyway, gawk is available on almost all unix platform ( and i'm using gawk )

1 (共1页)
进入Unix版参与讨论
相关主题
Re: 如何用grep查找子目录下的文件?How to use sed to add newline character?
sed? awk? or mak a program?about vi.
how to grep a string in all sub-dirs?paste command 里面的 -
how to escape both ' and " from tcsh?SOSSSS! Passwd file broken
请帮忙看看这个问题a question about renaming.
How do i get a list of all computers?如何把一个目录下的文件名全部改成小写?
vi 一问.[转载] How to list the files with specific permission?
error in my function "write_log"shell programming problems
相关话题的讨论汇总
话题: name话题: user话题: awk话题: grep话题: use