LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-22-2010, 02:24 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
Formatting Help needed(Sed)


I have a file called abc.txt which has following contents.

10.180.8.231=31608
10.180.8.232=29011
10.180.8.233=31606
10.180.8.234=40501
10.180.8.235=32591
10.180.8.236=31605
10.180.8.237=30561
10.180.8.238=14231

How would i find a ip address having maximum number of ram available.
Here it is 10.180.8.234 which has 40501 mb ram

I used to run the following command to get the ip with maximum ram.
sort -n -t '=' +1 abc.txt | sed -n '$p' | awk -F "=" '{print $1}'

But since i moved to new server which has older version of sort it gives me an error saying file abc.txt doesnt exist.
Please suggest how would i modify the command so that it should work fine on new server.
 
Old 06-22-2010, 02:35 AM   #2
mobinskariya
Member
 
Registered: Sep 2007
Location: Kerala, India
Distribution: ubuntu 10.04
Posts: 367

Rep: Reputation: 55
what about this
Code:
sort --key=2 -t "=" abc.txt -r |awk -F = '{print$1}'
 
Old 06-22-2010, 03:02 AM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
Another alternative
Code:
cat abc.txt | tr "=" " " | sort -k 2 -r | head -1
 
Old 06-22-2010, 12:46 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

And one that use awk only:

awk -F"=" 'BEGIN { prev = 0 ; ipnum = 0} {if ( $2 >= prev ) { prev = $2 ; ipnum = $1 } } END { print ipnum }' abc.txt

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
formatting help needed. pinga123 Linux - Newbie 3 06-23-2010 07:56 AM
[SOLVED] Little formatting help needed. pinga123 Linux - Newbie 7 03-23-2010 09:33 AM
Output formatting help needed. pinga123 Linux - Newbie 8 11-03-2009 07:34 AM
Using awk/sed to convert linefeed to csv, with some formatting jaykup Programming 1 04-03-2009 06:18 PM
sed or other formatting command help SeT Linux - General 1 10-13-2004 07:57 PM


All times are GMT -5. The time now is 08:36 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration