Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    56

    Unanswered: how to find the file name format in the current directory

    I have a requirement to find out the file name format .

    I had to look for a file in the current directory which is in the format YYYYMM_PI_710_AT.dat

    Got to write a shell script on this ..

    Need your help


    Thanks in advance !!
    Last edited by MIKELALA; 06-20-14 at 15:10. Reason: title wrong

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Code:
    ls |grep "......_PI_..._AT\.dat"

  3. #3
    Join Date
    May 2014
    Posts
    6
    hi,

    Code:
    find $searchDir -type f -regextype posix-basic -regex '.*/[0-9]\{6\}_PI_710_AT.dat$'
    if no searchDir is defined, then the current directory will be used.

    parsing `ls' output is usually a bad idea

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    parsing `ls' output is usually a bad idea
    An explanation of why you think this would be nice. I'd like to learn something too.

    Your solution by the way only works on systems that have the GNU utilities installed. Unix systems do not usually have it as standard equipment, but Linux systems do.
    When I ran your solution, I got the following output:
    Code:
    # ./t                                                                           
    /usr/gnu/bin/find: warning: you have specified the -regextype option after a non
    -option argument -type, but options are not positional (-regextype affects tests
     specified before it as well as those specified after it).  Please specify optio
    ns before other arguments.   
                                                       
                                                                                    
    # cat t                                                                         
    searchDir=/tmp                                                                  
    /usr/gnu/bin/find $searchDir -type f -regextype posix-basic -regex '.*/[0-9]\{6\
    }_PI_710_AT.dat$'                                                               
    #
    Last edited by kitaman; 06-24-14 at 20:40.

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

    Cool

    Kitaman is right, but you can use a combined solution (albeit fuzzy):
    Code:
    ==> find $searchDir -type f -name "*_PI_*_AT.dat" -ls
    17295    1 -rw-r--r--  1 oracle    dba            197 Jun 25 09:08 ./201304_PI_663_AT.dat
    17287    1 -rw-r--r--  1 oracle    dba            197 Jun 25 09:08 ./201305_PI_710_AT.dat
    17288    1 -rw-r--r--  1 oracle    dba            197 Jun 25 09:08 ./201305_PI_711_AT.dat
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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