Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I need to pick files of the format "REUSE_212_001_20080519_1.txt" from a specified directory with a condition that the alphabets used in the pattern 'REUSE' can be in any case. ...
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    1

    Regular Expression Anamoly

    Hi,

    I need to pick files of the format "REUSE_212_001_20080519_1.txt" from a specified directory with a condition that the alphabets used in the pattern 'REUSE' can be in any case.

    To implement this logic in my shell script, I am using a regular expression as mentioned in the below scriptlet;
    for filename in `ls ${1}\[Rr][Ee][Uu][Ss][Ee]_[0-9][0-9][0-9]_0[0-1]1_[1-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9]_[1-9].txt`
    do
    echo $filename
    done

    This gives me the output /export/home/schatter/FTP_scripts/report/[Rr][Ee][Uu][Ss][Ee]_[0-9][0-9][0-9]_0[0-1]1_[1-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9]_[1-9].txt: No such file or directory

    Whereas,

    Listing the file with cat command using this regular expression gives me the file contents as mentioned below;

    cat /export/home/schatter/FTP_scripts/report/[Rr][Ee][Uu][Ss][Ee]_[0-9][0-9][0-9]_0[0-1]1_[1-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9]_[1-9].txt

    gives the output
    000198,17May2009-05:49:27,000000004
    07000000058,17May2009-04:00:02,22909
    07000000059,17May2009-04:00:02,22909
    07000000060,17May2009-04:00:02,22909
    07000000061,17May2009-04:00:02,22909
    END_OF_DATA

    Can anyone please suggest me the reason and the description of this behavior ?

    Thanking in anticipation.

    -Soumen.

  2. #2
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    There is a little problem in your script:
    for filename in `ls ${1}\[Rr][Ee][Uu]
    should be
    for filename in `ls ${1}/[Rr][Ee][Uu]

Posting Permissions

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