Unix/Linux Go Back    


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

Issue with wildcard in filename (AIX 7.1.0.0)

AIX


Tags
wildcard pattern matching

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-06-2018   -   Original Discussion by zulfi123786
zulfi123786's Unix or Linux Image
zulfi123786 zulfi123786 is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 13 January 2018, 7:00 AM EST
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
Issue with wildcard in filename (AIX 7.1.0.0)

Hi,

This has been pestering me for quite a while, any help will be highly appreciated

The current directory has a file with below name



Code:
npidata_20050523-20171210.csv

The below wildcard matched the above file



Code:
ls -ltr npidata_????????-201712??.csv

But when the part '201712' is put into a variable and use in the file name somehow does not match the file name



Code:
ls -ltr npidata_?????????${yyyymm}??.csv

Is there a way I can get around this ?
Sponsored Links
    #2  
Old Unix and Linux 01-06-2018   -   Original Discussion by zulfi123786
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 24 February 2018, 10:59 AM EST
Location: Amsterdam
Posts: 11,735
Thanks: 536
Thanked 3,407 Times in 3,002 Posts
I cannot reproduce this:

Code:
$ touch npidata_20050523-20171210.csv
$ ls -ltr npidata_????????-201712??.csv
-rw-r--r--  1 scrutinizer  staff  0 Jan  6 20:49 npidata_20050523-20171210.csv
$ yyyymm=201712
$ ls -ltr npidata_?????????${yyyymm}??.csv
-rw-r--r--  1 scrutinizer  staff  0 Jan  6 20:49 npidata_20050523-20171210.csv

I did notice you used a ? instead of a -, but since a ? matches a - that is still a match.

Code:
$ ls -ltr npidata_????????-${yyyymm}??.csv
-rw-r--r--  1 scrutinizer  staff  0 Jan  6 20:49 npidata_20050523-20171210.csv

What shell are you using?

Last edited by Scrutinizer; 01-06-2018 at 03:59 PM..
Sponsored Links
    #3  
Old Unix and Linux 01-06-2018   -   Original Discussion by zulfi123786
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 24 February 2018, 5:23 AM EST
Location: San Jose, CA, USA
Posts: 11,089
Thanks: 618
Thanked 3,865 Times in 3,307 Posts
In addition to what Scrutinizer already asked...

What command (exactly) did you use to set the the variable yyyymm?
    #4  
Old Unix and Linux 01-06-2018   -   Original Discussion by zulfi123786
zulfi123786's Unix or Linux Image
zulfi123786 zulfi123786 is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 13 January 2018, 7:00 AM EST
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
I am using ksh and for the variable, I hard coded the value


Code:
yyyymm=20171210

Sponsored Links
    #5  
Old Unix and Linux 01-06-2018   -   Original Discussion by zulfi123786
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 24 February 2018, 5:23 AM EST
Location: San Jose, CA, USA
Posts: 11,089
Thanks: 618
Thanked 3,865 Times in 3,307 Posts
Quote:
Originally Posted by zulfi123786 View Post
I am using ksh and for the variable, I hard coded the value


Code:
yyyymm=20171210
That would be appropriate if the variable had been named yyyymmdd and you had used the filename matching pattern:


Code:
ls -ltr npidata_?????????${yyyymmdd}.csv

instead of:


Code:
ls -ltr npidata_?????????${yyyymm}??.csv

For the filename matching pattern you're using, you needed to set yyyymm using:


Code:
yyyymm=201712

instead of:


Code:
yyyymm=20171210

Sponsored Links
    #6  
Old Unix and Linux 01-07-2018   -   Original Discussion by zulfi123786
zulfi123786's Unix or Linux Image
zulfi123786 zulfi123786 is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 13 January 2018, 7:00 AM EST
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
well the actual reason of doing it this way was because I do not know the day part of the date which is why the pattern matching Linux
Sponsored Links
    #7  
Old Unix and Linux 01-07-2018   -   Original Discussion by zulfi123786
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 24 February 2018, 10:59 AM EST
Location: Amsterdam
Posts: 11,735
Thanks: 536
Thanked 3,407 Times in 3,002 Posts
OK, but there is a mismatch this way so you would need to adapt the date. You could for example cut off the last two digits:


Code:
$ yyyymmdd=20171210
$ ls -ltr npidata_?????????${yyyymmdd%??}??.csv
-rw-r--r--  1 scrutinizer  staff  0 Jan  6 20:49 npidata_20050523-20171210.csv
$


Last edited by Scrutinizer; 01-08-2018 at 11:49 AM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
rbatte1 (01-08-2018)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Issue when printing filename through cygwin using a variable with awk alvinoo Shell Programming and Scripting 1 06-17-2015 11:44 PM
Waiting for wildcard filename to exists in while loop Amey Joshi Emergency UNIX and Linux Support 4 09-13-2014 05:17 AM
grep pipe filename print issue shifahim UNIX for Dummies Questions & Answers 16 08-04-2011 05:57 AM
Issue "Error 404" when upgrade AIX 5300-05-CSP-0000 to AIX (5300-09-02-0849) gamonhon AIX 0 02-17-2009 12:36 AM
Find wildcard .shtml files in wildcard directories and removing them- How's it done? Neko UNIX for Dummies Questions & Answers 1 06-27-2001 10:06 AM



All times are GMT -4. The time now is 12:02 PM.