Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: getting mul...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 2188 of 2236
Post > Topic >>

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




 4 Posts in Topic:
getting multiple line matches to single line for gcc --version
Jeff <jeep@[EMAIL PROT  2008-03-13 09:35:48 
Re: getting multiple line matches to single line for gcc --versi
gazelle@[EMAIL PROTECTED]  2008-03-13 16:39:53 
Re: getting multiple line matches to single line for gcc --versi
Ralf Damaschke <rwspam  2008-03-13 17:03:48 
Re: getting multiple line matches to single line for gcc --versi
Danijel Tasov <dtasov@  2008-03-13 22:17:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 2:22:09 CDT 2008.