The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading a file and writing the file name to a param file. thebeginer UNIX for Advanced & Expert Users 1 10-05-2007 04:38 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 05:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-22-2007
pyramimi111 pyramimi111 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 1
help with file name

His may seem simple to many but I have no clue
Need some urgent help please

How can I make this statement evaluate to true if the actual DataFile can have an extension of either .dat or .txt

what I'm trying to say is my datafile could have a name like
ABC_20070323_xyz.dat
or
ABC_20070323_xyz.txt

now the trick is also in the if statement
These for example are now valid
ABC_20070323_xyz.dat.gz
or
ABC_20070323_xyz.dat.Z
or
ABC_20070323_xyz.txt

notice the .txt file can also have the option of no compression


ControlFileName=${ControlFile##*/};
DataFile="${SOURCE_DATA_PATH}/${ControlFileName%.*}.dat";

if [[ -f "${DataFile}" ]]; then
X=1; # Do nothing
elif [[ -f "${DataFile}.gz" ]]; then
DataFile=${DataFile}.gz;
elif [[ -f "${DataFile}.Z" ]]; then
DataFile=${DataFile}.Z;
else
Log ERROR "Could not find data file for Data File=${DataFile} [or .dat.gz or .dat.Z]";
returnStatus=1;
break;
fi;
  #2 (permalink)  
Old 03-22-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
In ksh you can make patterns that will match any of those possible names, but an if statement using them would fail if more than one name matches the pattern. So you could loop through all of the names...

$ ls
xyz.txt.Z xyz.txt.gz
$ name=xyz
$ for f in ${name}.@(dat|txt)?(.gz|.Z) ; do echo $f ; done
xyz.txt.Z
xyz.txt.gz
$

Or if you don't care which file you have, maybe something like this:

$ list=$(echo ${name}.@(dat|txt)?(.gz|.Z))
$ echo $list
xyz.txt.Z xyz.txt.gz
$ onename=${list%% *}
$ echo $onename
xyz.txt.Z
$
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0