For Programmers: Free Programming Magazines  


Home > Archive > AWK > March 2008 > getting multiple line matches to single line for gcc --version









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author getting multiple line matches to single line for gcc --version
Jeff

2008-03-13, 9:59 pm

Im trying to use awk to extract the version of gcc in a makefile,
but for now Im trying it on the command line to get it to work.

Since the output of gcc --version is multiline, Im getting $3 of every
line:

4.1.2
2006
free
even

for this: gcc --version | awk '{print $3}'

How do I get it to just take the first line?
Ive read the man page and it seems like I need to
do something with RS= but Im unsure how to make it
work. I thought setting RS="" or RS=" " would make it
all a single line, but awk complains that I cannot set
RS to either of those.

Thanks for your help
Kenny McCormack

2008-03-13, 9:59 pm

In article <225d624e-bece-45bf-afcf-afc4dac25760@m3g2000hsc.googlegroups.com>,
Jeff <jeep@rahul.net> wrote:
>Im trying to use awk to extract the version of gcc in a makefile,
>but for now Im trying it on the command line to get it to work.
>
>Since the output of gcc --version is multiline, Im getting $3 of every
>line:
>
>4.1.2
>2006
>free
>even
>
>for this: gcc --version | awk '{print $3}'


gcc --version | awk '{print $3;exit}'

Ralf Damaschke

2008-03-13, 9:59 pm

Jeff wrote:

> Im trying to use awk to extract the version of gcc in a
> makefile, but for now Im trying it on the command line to get
> it to work.
>
> Since the output of gcc --version is multiline,


Is it?
$ gcc --version
2.5.8
$

> Im getting $3
> of every line:
>
> 4.1.2
> 2006
> free
> even
>
> for this: gcc --version | awk '{print $3}'
>
> How do I get it to just take the first line?
> Ive read the man page and it seems like I need to
> do something with RS= but Im unsure how to make it
> work. I thought setting RS="" or RS=" " would make it
> all a single line, but awk complains that I cannot set
> RS to either of those.


Don't mess with RS, just exit after the first record processed.
$ gcc --version | awk '{ print $(NF); exit 0 }'

That works for both versions in question.

Ralf
Danijel Tasov

2008-03-13, 9:59 pm

Jeff wrote:
> for this: gcc --version | awk '{print $3}'


no need for awk: gcc -dumpversion

bye,
Da.Ta
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com