×
UNIX.COM Login
Username:
Password:  
Show Password






👤


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)

Tags
wildcard pattern matching

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-06-2018
zulfi123786 zulfi123786 is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 21 March 2018, 8:21 AM EDT
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 01-06-2018
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 16 July 2018, 12:01 PM EDT
Location: Amsterdam
Posts: 11,853
Thanks: 546
Thanked 3,469 Times in 3,057 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 02:59 PM..
Sponsored Links
    #3  
Old 01-06-2018
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 16 July 2018, 1:02 AM EDT
Location: San Jose, CA, USA
Posts: 11,406
Thanks: 649
Thanked 3,970 Times in 3,393 Posts
In addition to what Scrutinizer already asked...

What command (exactly) did you use to set the the variable yyyymm?
    #4  
Old 01-06-2018
zulfi123786 zulfi123786 is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 21 March 2018, 8:21 AM EDT
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 01-06-2018
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 16 July 2018, 1:02 AM EDT
Location: San Jose, CA, USA
Posts: 11,406
Thanks: 649
Thanked 3,970 Times in 3,393 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 01-07-2018
zulfi123786 zulfi123786 is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 21 March 2018, 8:21 AM EDT
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
Sponsored Links
    #7  
Old 01-07-2018
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 16 July 2018, 12:01 PM EDT
Location: Amsterdam
Posts: 11,853
Thanks: 546
Thanked 3,469 Times in 3,057 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 10:49 AM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
rbatte1 (01-08-2018)
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:44 PM
Waiting for wildcard filename to exists in while loop Amey Joshi Emergency UNIX and Linux Support 4 09-13-2014 04:17 AM
grep pipe filename print issue shifahim UNIX for Dummies Questions & Answers 16 08-04-2011 04:57 AM
Issue "Error 404" when upgrade AIX 5300-05-CSP-0000 to AIX (5300-09-02-0849) gamonhon AIX 0 02-16-2009 11:36 PM
Find wildcard .shtml files in wildcard directories and removing them- How's it done? Neko UNIX for Dummies Questions & Answers 1 06-27-2001 09:06 AM



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

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.