- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- elif loop help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 08:19 PM
тАО06-20-2007 08:19 PM
I am trying to list files in a directory and if they are *.Z then uncompress or if they are *.gz then gunzip however the sytax I run will uncompress the *.Z files but error on the *.gz files, here is my syntax:
for COMPRESSED in `awk '{print $1}' list`
do
if [ -f *.Z ] ; then
echo "uncompressing $COMPRESSED"
uncompress $COMPRESSED
elif [ -f *.gz ] ; then
echo "uncompressing gzipped $COMPRESSED"
gunzip $COMPRESSED
else
continue
fi
done
any help would be greatly appreciated or another solution?
Please note that there thousands of files and running 2 find commands would put additional load to the server.
Thanks
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 08:29 PM
- Tags:
- pattern
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 08:32 PM
тАО06-20-2007 08:32 PM
Re: elif loop help
Oops, that assumes you only have filename in your file "list" and not other columns you want to ignore.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 08:40 PM
тАО06-20-2007 08:40 PM
Re: elif loop help
yes the list file has 3 fields so awk would work however I will try you example with the while loop ie:
while read FILE DATE YEAR
do
if [[ FILE = *.Z ]] ; then
etc
etc
done < list
will let you know how I get on
cheers
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 08:46 PM
тАО06-20-2007 08:46 PM
Re: elif loop help
works a treat and picked up something new:
for files in $(
etc.
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 08:49 PM
тАО06-20-2007 08:49 PM
Re: elif loop help
if think you want to test $COMPRESSED
either [ -f $COMPRESSED ]
if $COMPRESSED is the filename including the postfix .Z (.gz)
or [ -f ${COMPRESSED}.Z ]
if $COMPRESSED does not have the .Z
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 09:10 PM
тАО06-20-2007 09:10 PM
Re: elif loop help
for COMPRESSED in ...; do
case $COMPRESSED in
*.Z) echo "uncompressing $COMPRESSED"
;;
*.gz|*.tgz) echo "uncompressing gzipped $COMPRESSED"
;;
*) echo "not one of those guys"
;;
esac
done
I used "|" above to allow both patterns.
- Tags:
- case
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 10:02 PM
тАО06-20-2007 10:02 PM
Re: elif loop help
I like that as it appears to be very effiecient.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-20-2007 10:03 PM
тАО06-20-2007 10:03 PM