If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > list out the filename if less than

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-20-09, 04:50
ymho ymho is offline
Registered User
 
Join Date: Jul 2006
Posts: 107
list out the filename if less than

there are 3 files but want to list out the filename if less than a.20090120

a.20090119
a.20090120
a.20090121
Reply With Quote
  #2 (permalink)  
Old 01-20-09, 08:45
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
Talking awk

One way would be to use awk:
Code:
ls -1 a.*|awk 'substr($0,3) < '20090120' {print $0}'
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 01-20-09, 08:51
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
Quote:
Originally Posted by ymho
there are 3 files but want to list out the filename if less than a.20090120

a.20090119
a.20090120
a.20090121
I can understand wanting to see the last file, or the last x files, but why would you want this type of functionality in a program? (just curious)
Mike
Reply With Quote
  #4 (permalink)  
Old 01-20-09, 16:41
freeBatjko freeBatjko is offline
Registered User
 
Join Date: Mar 2008
Posts: 89
Quote:
Originally Posted by mike_bike_kite
I can understand wanting to see the last file, or the last x files, but why would you want this type of functionality in a program? (just curious)
Mike
Probably really just a date kind of thing. In this case it might be better to either use the file creation date, or use that part of the file name that represents a date and use date functions?
__________________
"My brain is just no good at being a relational Database - my relations suck real bad!"
Reply With Quote
  #5 (permalink)  
Old 01-20-09, 16:52
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
I understand it's a date thing. I just can't see why you'd have a program to pull all the files since a set date - that seems to be more something you'd do by hand when the need arose. There's loads of possible solutions but I just wanted to know whether this was a one off task, in which case I'd just use ls and tail, or it's for a program and I'd probably either use awk or the find command where files are dated earlier than a given file. I just wanted to know why he was after the functionality
Reply With Quote
  #6 (permalink)  
Old 01-21-09, 00:35
ymho ymho is offline
Registered User
 
Join Date: Jul 2006
Posts: 107
Quote:
Originally Posted by mike_bike_kite
I understand it's a date thing. I just can't see why you'd have a program to pull all the files since a set date - that seems to be more something you'd do by hand when the need arose. There's loads of possible solutions but I just wanted to know whether this was a one off task, in which case I'd just use ls and tail, or it's for a program and I'd probably either use awk or the find command where files are dated earlier than a given file. I just wanted to know why he was after the functionality
thanks mike_bike_kite ...

i have output files in every office days(e.g excluding holidays .. etc) which is named in x.yyyymmdd (where yyyymmdd is processing date).

Hence, i would like to return the file of a previous day of a specific date requested by user ...
Reply With Quote
  #7 (permalink)  
Old 01-21-09, 05:20
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
Then LKBrwn_DBA's solution seems perfect.

You could also just change the question to the user so they end up supplying the correct day to search for - the current method just seems to be creating work for yourself.
Reply With Quote
Reply

Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On