Re: getting multiple line matches to single line for gcc --version
by Ralf Damaschke <rwspam@[EMAIL PROTECTED]
>
Mar 13, 2008 at 05:03 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