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 )
|