The UNIX and Linux Forums  

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
Problem with find and tar venu_nbk UNIX for Dummies Questions & Answers 2 11-20-2006 10:41 AM
FIND/GREP problem dfb500 UNIX for Dummies Questions & Answers 1 11-13-2006 11:13 AM
problem with find braindrain Shell Programming and Scripting 2 03-29-2006 01:33 PM
Problem with find ! -newer dbfree Shell Programming and Scripting 3 12-19-2005 10:56 PM
Another Find Problem sethkor Shell Programming and Scripting 6 02-24-2005 07:56 PM

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 08-10-2005
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
Question Problem with `find ...`

Hi all,
Have the following snippet of code that I'm having trouble trying to work ...

The snippet of code is running on our Production Server and the intent is to copy the second most recent IDE file across from the Development Server.

I have the following files defined in $DEVLOC ...
Code:
-rw-r--r--   1 root       sys         245751 Aug  1 09:23 050729.14:20.ides.zip
-rw-r--r--   1 root       sys         245751 Aug  1 09:23 050729.14:32.ides.zip
-rw-r--r--   1 root       sys         245751 Aug  1 09:23 050729.15:18.ides.zip
-rw-r--r--   1 root       sys         245751 Aug  1 09:23 050729.15:28.ides.zip
-rw-r--r--   1 root       sys         247925 Aug  1 09:23 050730.00:05.ides.zip
-rw-r--r--   1 root       sys         249305 Aug  1 09:23 050731.00:05.ides.zip
-rw-r--r--   1 root       sys         253966 Aug  1 09:23 050801.00:06.ides.zip
-rw-r--r--   1 root       sys         121667 Aug  1 23:18 050802.00:05.ides.zip
-rw-r--r--   1 root       sys         128756 Aug  2 19:31 050803.00:05.ides.zip
-rw-r--r--   1 root       sys         131843 Aug  3 19:27 050804.00:05.ides.zip
-rw-r--r--   1 root       sys         137142 Aug  4 13:44 050805.00:05.ides.zip
-rw-r--r--   1 root       sys         143807 Aug  5 19:33 050806.00:05.ides.zip
-rw-r--r--   1 root       sys         146817 Aug  6 21:22 050807.00:05.ides.zip
-rw-r--r--   1 root       sys         146817 Aug  6 21:22 050808.00:05.ides.zip
-rw-r--r--   1 root       sys         150047 Aug  8 23:34 050809.00:05.ides.zip
-rw-r--r--   1 root       sys         155809 Aug  9 23:17 050810.00:05.ides.zip
I'm tried (in vain) initially to assign the most recent file, but business now requires second most recent (for QA reasoning).

I'm sure that I'm missing something really simple; just need a kick in the pants to have someone point it out for me; not having used `find` in scripts prior.
Code:
IDEtoFind=`find $DEVLOC -name \*.ides.zip -mtime -01 -print`
echo "Finding : $DEVLOC/$IDEtoFind" >>$templog
echo "Finding : $DEVLOC/$IDEtoFind"
echo "Copying : $DEVLOC/$IDEtoFind" >>$templog
echo "     To : $tmp/$downloadfile" >>$templog
echo "Copying : $DEVLOC/$IDEtoFind"
echo "     To : $tmp/$downloadfile"
cp $DEVLOC/$IDEtoFind $tmp/$downloadfile || error_copy
Any pointers would be of great assistance.
  #2 (permalink)  
Old 08-10-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,124
For 2nd most recent file, try:
ls -t | sed '1d;2q'
  #3 (permalink)  
Old 08-10-2005
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
Thanks for the reply Perderabo.

Reading this ...
a) Display files with most recent first.
b) with sed '1d;2q'
i. "1d" - delete first value
ii. "2q" - quit sed with value of second

Is that a reasonable estimate?
  #4 (permalink)  
Old 08-10-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Yes that is right.

From the man pages of sed,

Code:
q      Immediately quit the sed  script  without  processing  any  more
              input,  except  that  if  auto-print is not disabled the current
              pattern space will be printed.
Vino
  #5 (permalink)  
Old 08-10-2005
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
Many thanks for the confirmation Vino.
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 09:12 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