Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2006
    Posts
    115

    Unanswered: 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

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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

  4. #4
    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!"

  5. #5
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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

  6. #6
    Join Date
    Jul 2006
    Posts
    115
    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 ...

  7. #7
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •