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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compare dates... i_priyank Shell Programming and Scripting 3 09-21-2007 12:50 AM
compare dates ragha81 Shell Programming and Scripting 2 11-01-2006 06:17 PM
How to compare dates in C/C++ naan High Level Programming 1 08-28-2006 10:03 AM
How to compare two dates bankpro High Level Programming 5 01-24-2006 04:07 AM
latest status of an field in a log file encrypted UNIX for Dummies Questions & Answers 2 07-16-2004 04:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-04-2007
cvkishore cvkishore is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 1
Post Compare dates in a field and print the latest date row

Hi,

I need a shell script which should find the latest date in the field of file and print that line only. For eg.,

I have a file /date.log

Name Date Status
IBM 06/06/07 close
DELL 07/27/07 open
DELL 06/07/07 open
: : :

From this I want to find out the latest date (07/27/07) and print the line (DELL 07/27/07 open).

This is very very useful for me at my work. Please help me.

Thanks in Advance
CVKishore
  #2 (permalink)  
Old 08-04-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
mPrevCmpy="First"
sort input_file | while read mCmpy mDate mStatus
do
  if [ "${mCmpy}" != "${mPrevCmpy}" ]; then
    if [ "${mPrevCmpy}" != "First" ]; then
      echo ${mLine}
    fi
    mLatest=""
  fi
  mDD=`echo ${mDate} | cut -c1-2`
  mMM=`echo ${mDate} | cut -c4-5`
  mYY=`echo ${mDate} | cut -c7-8`
  mYYMMDD=${mYY}${mMM}${mDD}
  if [ "${mYYMMDD}" > "${mLatest}" ]; then
    mLine=${mCmpy}' '${mDate}' '${mStatus}
    mLatest=${mYYMMDD}
  fi
  mPrevCmpy=${mCmpy}
done
if [ "${mPrevCmpy}" != "First" ]; then
  echo ${mLine}
fi
Closed Thread

Bookmarks

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 10:09 PM.


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