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
Setting basename and dirname variable to simply script. liketheshell Shell Programming and Scripting 1 09-12-2007 01:36 PM
Extracting part of the basename madhunk Shell Programming and Scripting 3 02-13-2007 11:54 AM
reverse of basename braindrain Shell Programming and Scripting 7 10-03-2006 02:24 AM
need grep to output basename and line# zoo591 Shell Programming and Scripting 18 07-16-2005 10:34 AM
command find returned bash: /usr/bin/find: Argument list too long yacsil Shell Programming and Scripting 1 12-15-2003 06:38 PM

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 11-05-2007
sam_78_nyc sam_78_nyc is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 16
Using find command with awk or basename

Hi,
I am using the following command to extract any log files that are older than 3 days using the following command.

find DIR/LOGDIR -type f -mtime +3 |grep LOG > log_list.out
The results are
DIR/LOGDIR/1.LOG
DIR/LOGDIR/2.LOG
DIR/LOGDIR/3.LOG
DIR/LOGDIR/4.LOG


How do inculde (basename or awk ??) to extract just the file name instead of the complete directory like in log_list.out file.
1.LOG
2.LOG
3.LOG
4.LOG

Thanks all.
  #2 (permalink)  
Old 11-05-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
You can do something like that :
Code:
find DIR/LOGDIR -type f -mtime +3 -name '*LOG*' | sed 's_.*/__'  > log_list.out
Jean-Pierre.
  #3 (permalink)  
Old 11-05-2007
sam_78_nyc sam_78_nyc is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 16
Thanks

Great..
Thanks again..
  #4 (permalink)  
Old 11-05-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
You could also do this:

Code:
find DIR/LOGDIR -type f -mtime +3 -name '*LOG*' -exec basename {} \;
but this runs "basename" for each file. The "sed" command above is probably several hundred milliseconds faster.
  #5 (permalink)  
Old 11-05-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,512
if you have GNU find

Code:
find /path -type f -mtime +3 -name '*LOG*'  -printf "%f\n"
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 04:32 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