Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get "bigger" value combined with a text 1

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
0
0
PL

hello,
command produces output with many lines as on example:

Code:
    No filesets which have fixes for IV00149 are currently installed.
    All filesets for IV00151 were found.
    [red]All filesets for 71-01-031207_SP were found.
    All filesets for 71-00-041140_SP were found.
    All filesets for 71-01-021150_SP were found.[/red]

I need to get the biggest "value" in column 4 for lines like matched in red.
here are commands which seems to do the job:

Code:
# nim -o fix_query 710spot_res|grep -E '( [0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]_.. )'|awk 'BEGIN {max = 0} {if ($4>max) max=$4} END {print max}'
71-01-041216_SP

# nim -o fix_query 710spot_res|awk 'NF==6&&$1=="All"&&$2=="filesets"&&$3=="for"&&$5=="were"&&$6=="found."&&$4~/^[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]_..$/{print $4}'|sort -n|tail -1
71-01-041216_SP

is there any easier way? e.g. single awk 'oneliner' without multiple piping?





 
Hi

Maybe something like this :
Code:
nim -o fix_query 710spot_res |
awk 'NF==6&&$1$2$3=="Allfilesetsfor"&&$5$6=="werefound."&&$4~/^[0-9]{2}-[0-9]{2}-[0-9]{6}_..$/&&max<$4{max=$4}END{print max}'

Note that I added some further simplifications for readability, which may be an issue on your system :
[ul]
[li]Checking $1, $2 and $3 by their concatenate values may lead to erroneous matches. ( For example will also match "A llfilesetf or". Probably not a plausible menace.[/li] )
[li]Using [tt]{2}[/tt]-like quantifiers required [tt]--re_interval[/tt] switch in older [tt]gawk[/tt] versions and may not work in other implementations.[/li]
[/ul]


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top