The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print data between 2 lines in a file kamesh83 UNIX for Advanced & Expert Users 5 12-18-2008 12:14 PM
print out result from data file thms_sum Shell Programming and Scripting 8 01-30-2008 11:32 AM
Print Problem in UNIX. Need to know the option to specify the print paper size ukarthik HP-UX 1 06-07-2007 09:35 AM
Logging HP-UX print data pmaths UNIX for Dummies Questions & Answers 0 04-23-2007 08:45 AM
Unix Program for data and print miketaylor UNIX for Advanced & Expert Users 5 05-21-2002 10:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2008
Streetrcr Streetrcr is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
Print out a row of data

hi

im completely new at unix so dont hate me for asking what is probably the easiest question ever.

below is an extract of some data im processing. the first column is like a counter while the second is an ip address. i need to be able to output the ip address based on which has the largest counter number. as you can see the data is already sorted by the size of the counter. hence the output would be 66.249.66.103.

Code:
     65 138.130.16.56
     67 207.46.98.38
     79 65.214.44.112
     82 66.151.181.10
     94 209.191.65.248
     96 207.46.98.37
     97 207.46.98.39
    104 207.46.98.40
    178 66.249.65.167
    457 66.249.66.103
please help me do this, i have no idea how to do it. ALSO...please keep the answer simple otherwise i will just get lost
thanks
  #2 (permalink)  
Old 03-17-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
To print the last line of a file, use the "tail" command.

Code:
tail -n 1 filename
Conventionally, we would probably sort so that the top result is at the top, and use "head".

Don't worry about this part, I'm just giving you hints in case you want to develop your skills in the future.

Code:
sort -rn filename | head -n 1
If you want to split off the counter and just see the IP address, you can post-process the output from tail (or head, or any command) with a command like "cut" or "awk" or ... there's a myriad variations. I'll use awk here because it conveniently handles the space-padded format you are using (cut would have a problem with that);

Code:
tail -n 1 filename | awk '{print $2}'
awk is a full-blown scripting language so you could do all of this in awk, but I guess you are overwhelmed already.
  #3 (permalink)  
Old 03-17-2008
Streetrcr Streetrcr is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
thanks a lot. that was a big help. yeah i knew that awk could do it all, but i prefer to work through it step by step using the simple commands.

btw this is not related to my previous question, but when setting out unix code are there any ever new lines between pipelines? coz im writing a script and it has 8 pipelines at the moment which tends to get a bit messy. ie what is the correct setting out for longer unix code.
  #4 (permalink)  
Old 03-17-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
The shell allows you to split pipelines across multiple lines without any continuation character.

Code:
grep fnord /tmp/file |
nl |
sed -e 's/foo/bar/' |
cat -A |
whatever ...
In the general case, it's probably better to post a new question under a different topic title, because many readers only look at the topic titles and only read the ones they know the answer to (or find interesting, or don't know the answer to, depending on who they are and what they do).
  #5 (permalink)  
Old 03-17-2008
Streetrcr Streetrcr is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 10
great. thanks a lot for ur help
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0