Sponsored Content
Top Forums Shell Programming and Scripting Displaying lines of a file which have the highest number? Post 302415415 by Glyn_Mo on Thursday 22nd of April 2010 02:03:57 PM
Old 04-22-2010
Scrutinizer, many thanks.

I've had a problem when running this against another file though. The file contents are as follows:

Code:
bash-3.00$ cat release
ins_smo.sql-22                           1
lfa10ins.fmb-1                           1
lfa10ins.fmb-2                           1
lfa10ins.fmx-1                           1
lfa10ins.fmx-1                           2
lfa10ins.fmx-2                           1
lfa10ins.fmx-2                           2
pen_pack_05.pkb-8                        2
pkg_land_insp_capture_form.pkb-19        1
release_note_SAF10_Certification_1.doc-0 1
release_note_SAF10_Certification_1.doc-1 1
release_note_SAF10_Certification_1.doc-2 1
releasenote-1317                         1
saf09127.rdf-10                          1
saf09127.rdf-9                           1
saf09127.rep-10                          1
saf09127.rep-10                          2
saf09127.rep-9                           1
saf09127.rep-9                           2
saf1016c.fmb-1                           1
saf1016c.fmb-2                           1
saf1016c.fmx-1                           1
saf1016c.fmx-1                           2
saf1016c.fmx-2                           1
saf1016c.fmx-2                           2
saf1016m.fmb-1                           1
saf1016m.fmx-1                           1
saf1016m.fmx-1                           2
saf1016s.fmb-1                           1
saf1016s.fmx-1                           1
saf1016s.fmx-1                           2
bash-3.00$

When I run your command, I get the following returned:
Code:
saf09127.rep-9            2
releasenote-1317          1
ins_smo.sql-22            1
saf1016s.fmx-1            1
saf1016c.fmb-2            1
saf1016s.fmx-1            2
saf1016s.fmb-1            1
pen_pack_05.pkb-8         2
saf1016m.fmx-1            1
saf1016m.fmx-1            2
pkg_land_insp_capture_form.pkb-19 1
saf1016m.fmb-1            1
lfa10ins.fmx-2            1
lfa10ins.fmx-2            2
lfa10ins.fmb-2            1
release_note_SAF10_Certification_1.doc-2 1
saf1016c.fmx-2            1
saf1016c.fmx-2            2
saf09127.rdf-9            1
saf09127.rep-9            1

The problem is that objects
Code:
saf09127.rdf-9            1
saf09127.rep-9            1
saf09127.rep-9            2

... are being displayed, instead of
Code:
saf09127.rdf-10            1
saf09127.rep-10            1
saf09127.rep-10            2

Is there some problem when it's calculating double-figures?

I must the awk I'm seeing in these solutions is a bit beyond my current knowledge! Thanks to both. Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find the highest number in the file

Hi, I have a file a.txt and it has values in it Eg :- I need to read through the file and find the number that is the greatest in them all. Can any one assit me on this. Thanks (30 Replies)
Discussion started by: systemali
30 Replies

2. UNIX for Dummies Questions & Answers

Displaying specific lines in a file.

I'm trying to figure out how to display a certain line in a text file. I keep getting references to Tail and Head, and I know how these work, but i'm lost on how to find say the third out of the five lines and display only that. I thought maybe grep could help, but that doesn't seem likely. ... (3 Replies)
Discussion started by: MaestroRage
3 Replies

3. Shell Programming and Scripting

Displaying number of lines from file

Hi, I am using below command to display the number of line, but its returning no of lines along with file name. But i want only no of line in the variable p. Please help me on this? p=`wc -l "text file"` echo "$p" (6 Replies)
Discussion started by: shivanete
6 Replies

4. Shell Programming and Scripting

Displaying lines of a file where the second field matches a pattern

Howdy. I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited? Example: You are... (3 Replies)
Discussion started by: LordJezoX
3 Replies

5. 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

6. Homework & Coursework Questions

Displaying specific lines from a CSV file

1. The problem statement, all variables and given/known data: Display from a csv file, birthdays that occur today. If there are no birthdays today, the next one in the year. 2. Relevant commands, code, scripts, algorithms: The csv file is ordered from older to younger (ie. the most recent... (8 Replies)
Discussion started by: Adzi
8 Replies

7. 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

8. 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

9. 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

10. Shell Programming and Scripting

Adding user name to file, and then displaying new line number

Hi all - I'm completely stumped by a script I'm working on... The short version is I have a file called 'lookup' and in it are hundreds of names (first and last). I have a script that basically allows the user to enter a name, and what I need to have happen is something like this: Record... (8 Replies)
Discussion started by: sabster
8 Replies
fmt(1)								   User Commands							    fmt(1)

NAME
fmt - simple text formatters SYNOPSIS
fmt [-cs] [-w width | -width] [inputfile]... DESCRIPTION
fmt is a simple text formatter that fills and joins lines to produce output lines of (up to) the number of characters specified in the -w width option. The default width is 72. fmt concatenates the inputfiles listed as arguments. If none are given, fmt formats text from the standard input. Blank lines are preserved in the output, as is the spacing between words. fmt does not fill nor split lines beginning with a `.' (dot), for compatibility with nroff(1). Nor does it fill or split a set of contiguous non-blank lines which is determined to be a mail header, the first line of which must begin with "From". Indentation is preserved in the output, and input lines with differing indentation are not joined (unless -c is used). fmt can also be used as an in-line text filter for vi(1). The vi command: !}fmt reformats the text between the cursor location and the end of the paragraph. OPTIONS
-c Crown margin mode. Preserve the indentation of the first two lines within a paragraph, and align the left margin of each subsequent line with that of the second line. This is useful for tagged paragraphs. -s Split lines only. Do not join short lines to form longer ones. This prevents sample lines of code, and other such for- matted text, from being unduly combined. -w width | -width Fill output lines to up to width columns. OPERANDS
inputfile Input file. ENVIRONMENT VARIABLES
See environ(5) for a description of the LC_CTYPE environment variable that affects the execution of fmt. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
nroff(1), vi(1), attributes(5), environ(5) NOTES
The -width option is acceptable for BSD compatibility, but it may go away in future releases. SunOS 5.11 9 May 1997 fmt(1)
All times are GMT -4. The time now is 08:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy