Printing the lines of the string with highest value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing the lines of the string with highest value
# 1  
Old 07-26-2012
Printing the lines of the string with highest value

Please help .

The script need to first grep for all lines with "C:" as it contains a value

Here the value is 0

Code:
1,00:  This , is a good script  c:0

and then give output of the lines with top 3 highest value for c:

Code:
1,00:  This , is a nice script  c:9999
1,00:  This , is a good  script  c:9998
1,00:  This , is a  cool  script  c:9000
1,00:  This , is a   fun   script  c:12

So the output should be

Code:
1,00:  This , is a nice script  c:9999
 1,00:  This , is a good  script  c:9998
 1,00:  This , is a  cool  script  c:9000

---------- Post updated at 01:31 AM ---------- Previous

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 07-26-2012 at 12:22 PM..
# 2  
Old 07-26-2012
Code:
sort -t: -nr -k3 input.txt | head -3

# 3  
Old 07-26-2012
Quote:
Originally Posted by itkamaraj
Code:
sort -t: -nr -k3 input.txt | head -3

No that didnt work and i think you misunderstood

Not all lines in the file contain the word "c:" and the position of the word would also vary on the line , hence first c: needs to be grepped separately from the file and then the top 10 highest value for it should be printed for it

eg
1,00: This , is a nice script c:9999
1,00: This , is a good script c:9998
1,00: This , is a cool script c:9000
1,00: This , is a fun script c:12

So the output should be

1,00: This , is a nice script c:9999
1,00: This , is a good script c:9998
1,00: This , is a cool script c:9000
# 4  
Old 07-26-2012
Code:
awk '/c:/' infile |sort -t: -nr -k3  | head -3

grep "c:"  infile |sort -t: -nr -k3  | head -3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in printing n number of lines if a search string matches in a file

Hi I have below script which is used to grep specific errors and if error string matches send an email alert. Script is working fine , however , i wish to print next 10 lines of the string match to get the details of error in the email alert Current code:- #!/bin/bash tail -Fn0 --retry... (2 Replies)
Discussion started by: neha0785
2 Replies

2. Shell Programming and Scripting

Printing highest value from a list

Hi all, I'm trying to get the item with the maximum value, and was wondering if someone can help me with it. Heres my input file: apples 15 books 15 books 17 pens 12 pens 15 umbrella 13Here's what my output file should look like: apples 15 books 17 pens 15 umbrella 13 Can... (2 Replies)
Discussion started by: r4v3n
2 Replies

3. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 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

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

6. Shell Programming and Scripting

Printing 10 lines above and below the search string: help needed

Hi, The below code will search a particular string(say false in this case) and return me 10 lines above and below the search string in a file. " awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print("***********************************");print;c=a;}b{r=$ 0}' b=10 a=10 s="false" " ... (5 Replies)
Discussion started by: vimalm22
5 Replies

7. Shell Programming and Scripting

printing lines to a file from a particular string

Hi, A very Good Evening to All, I am writing a script for my application. I have a file with 1000 lines. Among that 1000 lines i am searching for a particular string. And from that string i need to pull all the data in to a seperate file. For example the contents of my file is as below. ... (4 Replies)
Discussion started by: intiraju
4 Replies

8. Shell Programming and Scripting

Remove lines of the same time stamp leaving the highest

Hi guys, I have a log that looks like that below. Columns 2 3 4 5 6 7 is the date/time stamp separated by comma. UUU,02,06,2010,10,00,00,00,0000000000000000,0000000000000000,0000000000001224 UUU,02,06,2010,10,05,00,00,0000000000000000,0000000000000000,0000000000001502... (2 Replies)
Discussion started by: borderblaster
2 Replies

9. Shell Programming and Scripting

Printing the lines which proceeds the particular string

Hi, We are facing some issues while finding the particular string. Our file is: cat 1.txt Node Name(s) Preparation fragment Partition: Transformation instance: Transformation: Applied rows: Affected rows: Rejected rows: Throughput(Rows/Sec): Throughput(Bytes/Sec): Last... (3 Replies)
Discussion started by: Amey Joshi
3 Replies

10. UNIX for Dummies Questions & Answers

Printing highest value from one column

Hi, I have a file that looks like this: s6 98 s6 91 s6 56 s5 32 s5 10 s5 4 So what I want to do is print only the highest value for each value in the column: So the file will look like this: s6 98 s5 32 Thanks (4 Replies)
Discussion started by: phil_heath
4 Replies
Login or Register to Ask a Question