Using find command with awk or basename | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Using find command with awk or basename

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-05-2007
sam_78_nyc sam_78_nyc is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 12 November 2011, 4:01 AM EST
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 11-05-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
 
Join Date: Apr 2004
Last Activity: 20 January 2014, 5:51 AM EST
Location: Bordeaux, France
Posts: 1,711
Thanks: 2
Thanked 61 Times in 57 Posts
You can do something like that :

Code:
find DIR/LOGDIR -type f -mtime +3 -name '*LOG*' | sed 's_.*/__'  > log_list.out

Jean-Pierre.
Sponsored Links
    #3  
Old 11-05-2007
sam_78_nyc sam_78_nyc is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 12 November 2011, 4:01 AM EST
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks

Great..
Thanks again..
    #4  
Old 11-05-2007
gus2000 gus2000 is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 17 November 2011, 6:36 PM EST
Posts: 160
Thanks: 0
Thanked 1 Time in 1 Post
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.
Sponsored Links
    #5  
Old 11-05-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 7 November 2013, 6:42 AM EST
Posts: 2,651
Thanks: 0
Thanked 16 Times in 16 Posts
if you have GNU find


Code:
find /path -type f -mtime +3 -name '*LOG*'  -printf "%f\n"

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
basename not working as expected from find -exec jelloir Shell Programming and Scripting 2 04-28-2012 08:58 AM
awk and basename kaboink UNIX for Dummies Questions & Answers 10 11-28-2011 06:48 AM
Need help with basename command linuxkid Shell Programming and Scripting 3 08-30-2010 02:58 PM
basename $0 kripssmart Shell Programming and Scripting 4 05-12-2009 05:13 AM
problem with output of find command being input to basename command... new_learner UNIX for Dummies Questions & Answers 2 12-14-2008 01:56 AM



All times are GMT -4. The time now is 02:42 AM.