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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comparison List of commands f_amshan UNIX for Advanced & Expert Users 1 08-19-2006 06:08 AM
List of Commands ArabOracle.com SUN Solaris 2 10-12-2005 01:03 AM
.sh_history contains the list of past commands yls177 UNIX for Dummies Questions & Answers 1 12-03-2002 03:15 AM
A Thorough List of FreeBSD commands?!? Kyser_Soze UNIX for Dummies Questions & Answers 1 10-20-2001 10:18 AM
List of Commands for Unix Please ShdwMaster UNIX for Dummies Questions & Answers 5 03-08-2001 06:28 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-16-2008
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
Stumble this Post!
list files commands

hi all scripting gurus,

need some guide and advise from you.

i'm trying to list all the files in the year 2004 and the file format is something like this: 11176MZ00004JV900004JVB00004JVCcDBU20041206.txt try to use the symbol ^ but somehow it does not help.

i try this as well: ls -ltr | grep 200401 | more and it does shows the files listed in 2004 but also in 2005 and 2006. any way i can refine this search?

can anyone help? many thanks.


wee
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-16-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
If there are files from 2005 and 2006 which coincidentally contain 200401 in their file name then you need to make the regular expression more exact. If the date is always just before a final .txt extension then grep 2004....\.txt$ might work better. (Just a dot means "any character" in a regular expression.)
Reply With Quote
  #3 (permalink)  
Old 04-16-2008
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
Stumble this Post!
Quote:
Originally Posted by era View Post
If there are files from 2005 and 2006 which coincidentally contain 200401 in their file name then you need to make the regular expression more exact. If the date is always just before a final .txt extension then grep 2004....\.txt$ might work better. (Just a dot means "any character" in a regular expression.)
hi era,

thanks for the guide. tried the command but getting this result:

spids111% ls -ltr |grep *2004....\.txt$* | more
No match
spids111%

somewhere gone wrong in my command line?

thanks again!

wee
Reply With Quote
  #4 (permalink)  
Old 04-16-2008
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
Stumble this Post!
Quote:
Originally Posted by lweegp View Post
hi era,

thanks for the guide. tried the command but getting this result:

spids111% ls -ltr |grep *2004....\.txt$* | more
No match
spids111%

somewhere gone wrong in my command line?

thanks again!

wee
it works!! sorry i put in the *...oops...many thanks!!

wee
Reply With Quote
  #5 (permalink)  
Old 04-16-2008
Registered User
 

Join Date: Oct 2005
Location: singapore
Posts: 86
Stumble this Post!
Quote:
Originally Posted by lweegp View Post
it works!! sorry i put in the *...oops...many thanks!!

wee
apologies...one more question.

if i want to remove the files in 2004 what is the next command i need to put in? using rm command? like this:

spids111% ls -ltr | grep 2004....\.txt$ | rm * ?
Reply With Quote
  #6 (permalink)  
Old 04-16-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
rm doesn't read standard input, it expects the files to remove on its command line. Use xargs or backticks.

Code:
rm `ls -ltr | grep 2004....\.txt$`
or

Code:
ls -ltr | grep 2004....\.txt$ | xargs rm
Try it with "echo" instead of "rm" to make sure that you're doing the right thing.
Reply With Quote
  #7 (permalink)  
Old 04-16-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
(Weird, double post, sorry.)

Last edited by era; 04-16-2008 at 02:29 AM. Reason: Double post!?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0