Sponsored Content
Top Forums Shell Programming and Scripting find the highest number in the file Post 302069227 by tmarikle on Thursday 23rd of March 2006 12:31:48 PM
Old 03-23-2006
Whoops, you're right, I missed the point. Here's another quick stab at it (more for myself at any rate):
Code:
print "test.1.0.0.1.tar.gz
test3.1.2.3.9.tar.gz
test3.1.2.3.4.tar.gz
test3.1.2.3.11.tar.gz
test3.1.2.3.10.tar.gz
test3.1.0.0.4.tar.gz
test56.1.1.1.1.tar.gz
test1.1.0.0.1.tar.gz
test12.1.0.0.1.tar.gz
test2.1.2.1.2.tar.gz
test23.2.0.3.1.tar.gz
test3.1.0.0.1.tar.gz
test32.1.1.1.1.tar.gz
test33.1.1.1.1.tar.gz
test34.1.1.1.1.tar.gz
test4.2.2.2.2.tar.gz
test5.1.1.1.1.tar.gz
test8.1.1.1.1.tar.gz" | 
nawk -F\. '{
    filename=$0
    gsub (/^[a-z]*[0-9]*\./,"") 
    gsub (/[a-z]*/,"") 
    sub (/\.*$/,"")
    j=0
    for (i=1;i<=NF;i++) { j=j+($(NF-i+1)*(i^10)) }
    arr[j OFS n++]=filename
}
END {
    for (i in arr) print i, arr[i]
}' | nawk '{print $1":"$3}' | sort | nawk -F: '{print $2}'

Code:
test.1.0.0.1.tar.gz
test1.1.0.0.1.tar.gz
test12.1.0.0.1.tar.gz
test3.1.0.0.1.tar.gz
test3.1.0.0.4.tar.gz
test32.1.1.1.1.tar.gz
test33.1.1.1.1.tar.gz
test34.1.1.1.1.tar.gz
test5.1.1.1.1.tar.gz
test56.1.1.1.1.tar.gz
test8.1.1.1.1.tar.gz
test2.1.2.1.2.tar.gz
test3.1.2.3.4.tar.gz
test3.1.2.3.9.tar.gz
test3.1.2.3.10.tar.gz
test3.1.2.3.11.tar.gz
test23.2.0.3.1.tar.gz
test4.2.2.2.2.tar.gz

and
Code:
print "
-r-xr-xr-x 1 root other 715 Aug 23 2005 /spare3/ARCHIVE/test3.1.2.3.9.tar.gz
-r-xr-xr-x 1 root other 719 Aug 23 2005 /spare3/ARCHIVE/test3.1.2.3.4.tar.gz
-r-xr-xr-x 1 root other 1590 Nov 16 14:58 /spare3/ARCHIVE/test3.1.2.3.11.tar.gz
-r-xr-xr-x 1 root other 708 Aug 18 2005 /spare3/ARCHIVE/test3.1.2.3.10.tar.gz
-r-xr-xr-x 1 root other 1661 Oct 27 13:37 /spare3/ARCHIVE/test3.1.0.0.4.tar.gz
" |
nawk -F/ '{print $NF}' |
nawk -F\. '{
    filename=$0
    gsub (/^[a-z]*[0-9]*\./,"") 
    gsub (/[a-z]*/,"") 
    sub (/\.*$/,"")
    j=0
    for (i=1;i<=NF;i++) { j=j+($(NF-i+1)*(i^10)) }
    arr[j OFS n++]=filename
}
END {
    for (i in arr) print i, arr[i]
}' | nawk '{print $1":"$3}' | sort | nawk -F: '{print $2}'

Code:
test3.1.0.0.4.tar.gz
test3.1.2.3.4.tar.gz
test3.1.2.3.9.tar.gz
test3.1.2.3.10.tar.gz
test3.1.2.3.11.tar.gz

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding line with highest number in a file

Hi All, My file looks some thing like this, File 1: - A 10 B 30 C 5 D 25 E 72 F 23 now my requirement is to find the line with highest number in it, i;e the result should be E 72 Thanks in Advance (1 Reply)
Discussion started by: balu_puttaganti
1 Replies

2. Shell Programming and Scripting

Displaying lines of a file which have the highest number?

Hello Wondering if anybody may be able to advise on how I can filter the contents of the following file: <object_name>-<version> <Instance> GM_GUI_code.fmb-4 1 GM_GUI_code.fmb-5 1 GM_GUI_code.fmx-4 ... (7 Replies)
Discussion started by: Glyn_Mo
7 Replies

3. Shell Programming and Scripting

Extract the highest number out

Hi Gurus, I've using HPUX B.11.23 U ia64 with shell = sh. I've been having some problem get the highest number of this script. Actually I wanted to get the highest number from this listing (TEST123 data and based on this highest number, there will be email being sent out. For example,... (6 Replies)
Discussion started by: superHonda123
6 Replies

4. Shell Programming and Scripting

How to only display lines where a field has the highest number?

Hello Wondering if anybody can advise me how I can sort the below file so it only displays lines with the latest versions of an object? As you'll see some of the scripts listed in my file have more than one version number (version number is after the file extension). E.g. cdm_bri.pkb has... (2 Replies)
Discussion started by: Glyn_Mo
2 Replies

5. Shell Programming and Scripting

Bash, finding highest number in another file

i have a problem i am working on and am completely new to bash commands. I writing a script to read another file and output the max and Min number in the script. I must use variables to output the max and min numbers. grades = file with numbers in them. This is what i got so far. Thank You in... (3 Replies)
Discussion started by: ctanner10126
3 Replies

6. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

7. Programming

Help with find highest and smallest number in a file with c

Input file: #data_1 AGDG #data_2 ADG #data_3 ASDDG DG #data_4 A Desired result: Highest 7 Slowest 1 code that I try but failed to archive my goal :( #include <stdio.h> (2 Replies)
Discussion started by: cpp_beginner
2 Replies

8. Shell Programming and Scripting

Find highest number - working but need help!

Hello all, I am new to this and need some help or maybe steer me to the right direction! I wrote a script to get the highest number and prints it on the screen, the script basically asks the user to input numbers, and then prints the highest number! very simple it works like this $sh max.sh... (8 Replies)
Discussion started by: unknownsolo
8 Replies

9. Shell Programming and Scripting

Only print the entries with the highest number?

Just want to say this is great resources for all thing Unix!! cat tmp.txt A 3 C 19 A 2 B 5 A 1 A 0 C 13 B 9 C 1 Desired output: A 3 B 9 C 19 The following work but I am wondering if there is a better way to do it: (4 Replies)
Discussion started by: chirish
4 Replies

10. Shell Programming and Scripting

Sort from highest to lowest number

Hi Guys, I am looking for a way to sort the output below from the "Inuse" count from Highest to Lowest. Is it possible? Thanks in advance. user1 0.12 0.06 0 0.12 User Inuse Pin Pgsp Virtual Unit:... (4 Replies)
Discussion started by: jaapar
4 Replies
PIDOF(8)						Linux System Administrator's Manual						  PIDOF(8)

NAME
pidof -- find the process ID of a running program. SYNOPSIS
pidof [-s] [-c] [-n] [-x] [-o omitpid[,omitpid..]] [-o omitpid[,omitpid..]..] program [program..] DESCRIPTION
Pidof finds the process id's (pids) of the named programs. It prints those id's on the standard output. This program is on some systems used in run-level change scripts, especially when the system has a System-V like rc structure. In that case these scripts are located in /etc/rc?.d, where ? is the runlevel. If the system has a start-stop-daemon (8) program that should be used instead. OPTIONS
-s Single shot - this instructs the program to only return one pid. -c Only return process ids that are running with the same root directory. This option is ignored for non-root users, as they will be unable to check the current root directory of processes they do not own. -n Avoid stat(2) system function call on all binaries which are located on network based file systems like NFS. Instead of using this option the the variable PIDOF_NETFS may be set and exported. -x Scripts too - this causes the program to also return process id's of shells running the named scripts. -o omitpid Tells pidof to omit processes with that process id. The special pid %PPID can be used to name the parent process of the pidof pro- gram, in other words the calling shell or shell script. EXIT STATUS
0 At least one program was found with the requested name. 1 No program was found with the requested name. NOTES
pidof is actually the same program as killall5; the program behaves according to the name under which it is called. When pidof is invoked with a full pathname to the program it should find the pid of, it is reasonably safe. Otherwise it is possible that it returns pids of running programs that happen to have the same name as the program you're after but are actually other programs. Note that that the executable name of running processes is calculated with readlink(2), so symbolic links to executables will also match. SEE ALSO
shutdown(8), init(8), halt(8), reboot(8), killall5(8) AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl 01 Sep 1998 PIDOF(8)
All times are GMT -4. The time now is 08:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy