LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-21-2008, 09:45 AM   #1
craftereric
LQ Newbie
 
Registered: Mar 2008
Posts: 21

Rep: Reputation: 15
how to selectively print version numbers from log files


I have a series of log files in which I want to print version numbers (a.b.c.d) where a,b,c,d are integers. Once I find the pertinent line, is there a way to only print the version number from that line?

For example:
inputs:
2007-04-21 version 5.6.7.4 loading
Version 3.2.3.4 application

outputs:
5.6.7.4
3.2.3.4

I could use cut and sed but from the above examples the inputs are not consistent. I was looking for a more elegant way.
 
Old 04-21-2008, 10:02 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If the version number is always after the word Version or version (uppercase v) you can use awk like this
Code:
gawk '
/Version|version/ {
    for (i=1; i<=NF; i++)
      if ($i == "Version" || $i == "version")
        print $(i+1)
}' logfile
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Selectively moving files from a tree with a specific string anywhere in the path waterdragon900 Linux - Newbie 8 08-18-2008 09:57 AM
how do I make lpr always print page numbers fakie_flip Linux - Software 2 11-30-2007 07:03 PM
GLIBCXX selectively picking up the version moin Programming 1 09-08-2007 02:48 AM
print openoffice in arabic numbers error reaky Linux - General 0 06-02-2004 09:51 AM
Version numbers X11 Programming 2 04-09-2002 08:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration