Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

korn shell script - using wildcard in file search

Status
Not open for further replies.

bcdixit

Technical User
Nov 11, 2005
64
US

I have a file that is generated in the following format fb.d.v6.fbp.200606131452.gz i.e. the current TIME is also attached to YYYYMMDD

my question is how do i build a IF condition in my ksh script so that I can get something like this below
if [[ -s $IN_DIR_Frd/fb.d.v6.fbp.${DT}*.gz ]]

the ${DT} is basically a user inputed date in the YYYYMMDD format
basically I want it to ignore the TIME value after the date?

any help would be highly appreciated
 
Perhaps this ?
if [ -s $IN_DIR_Frd/fb.d.v6.fbp.${DT}[012][0-9][0-5][0-9].gz ]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
if [ -s $IN_DIR_Frd/fb.d.v6.fbp.${DT}[012][0-9][0-5][0-9].gz ]
is not working.
it thinks that '[012][0-9][0-5][0-9]' is part of the file name
 
is not working
What happens ? error message ? unexpected behaviour ? computer crash ?
Are you sure IN_DIR_Frd is properly populated ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
no crashes ..

yes the file in the directory exists.

the 'if' conditions still thinks [012][0-9][0-5][0-9] is part of the file name hence the condition fails and goes to the 'else' part of the code.


 
Hi,

Use only wild char star(*) protected by a backslash
Code:
if [ -s $IN_DIR_Frd/fb.d.v6.fbp.${DT}\*.gz ]
then
...
 
The problem with conditionals with wild cards are that they may fail if there is more than one match. i.e. if the directory has files fb.d.v6.fbp.070411.gz and fb.d.v6.fbp.070412.gz (today and yesterday) then the code
Code:
if [ -s $IN_DIR_Frd/fb.d.v6.fbp.${DT}[012][0-9][0-5][0-9].gz ]
expands to
Code:
[ -s fb.d.v6.fbp.070411.gz fb.d.v6.fbp.070412.gz ]
which is invalid

There are a number of options. If you insist on the -s flag then
Code:
for i in $IN_DIR_Frd/fb.d.v6.fbp.${DT}[012][0-9][0-5][0-9].gz 
do
  [[ -s $i ]] && do whatever
done

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top