Results 1 to 2 of 2

Thread: Find maximum value in file - unix awk command

  1. #1
    Senior Member vijay's Avatar
    Join Date
    May 2012
    Location
    Hyderabad
    Posts
    512

    Find maximum value in file - unix awk command

    I have file in my unix system. The file contains numbers in each line. I want to find the maximum value from these numbers using awk command. Sample data is shown below:

    Code:
    > cat digits.txt
    10
    20
    5
    60
    100
    7
    How to do that?

  2. #2
    Senior Member vijay's Avatar
    Join Date
    May 2012
    Location
    Hyderabad
    Posts
    512
    Awk solution:

    Code:
    awk 'max=="" || $1 > max {max=$1} END{ print max}' digits.txt

Similar Threads

  1. Replies: 1
    Last Post: 03-01-2013, 08:15 AM
  2. Replies: 1
    Last Post: 11-06-2012, 08:15 AM
  3. Replies: 1
    Last Post: 10-19-2012, 07:33 AM
  4. Replies: 1
    Last Post: 06-19-2012, 07:14 AM
  5. Replies: 2
    Last Post: 06-18-2012, 10:37 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •