LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-07-2004, 09:08 AM   #1
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
Pattern Matching Help in Bash script


Hi all.

I am wiritng a bash script to generate a web-based photo album/gallery.

I have the option of generating basic html file or php files with some enhanced features.

Prior to updating the gallery I want to delete a the previous exisiting html or php files.
Here's how I am trying to do it now:
Code:
####################################
#
#	Remove Old Pages
#
OLDPAGES="$(ls $DIRPATH*.[PpHh][HhTt][PpMm][Ll])"
for PAGES in $OLDPAGES
do
    echo "Removing:	$PAGES"
    rm -f $PAGES
done
That works fine for html files exist in the directory. If if only php files exist in the directory I get:
Code:
ls: /home/cfarley/webdata/wolverine/wip2/*.[PpHh][HhTt][PpMm][Ll]: No such file or directory
I know it's the final [Ll] causing it to fail. I know there are some wildcards that can be placed on the arguments to make them option but can't quite get it to work.

Anyone have and idea how to make the '[Ll]' optional?
 
Old 04-07-2004, 09:22 AM   #2
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Original Poster
Rep: Reputation: 32
One of the beauties of GNU/Linux.
Many ways to skin a cat:

I came up with this while playing around:
Code:
####################################
#
#	Remove Old Pages
#
OLDPAGES="$(ls|grep -i [php][html]| wc -w)"
if [ $OLDPAGES -ne 0 ]
    then
    OLDPAGES="$(ls|grep -i [php][html])"
    for PAGES in $OLDPAGES
    do
	echo "Removing:	$PAGES"
	rm -f $PAGES
    done
fi
Works like a charm.

I'd be interested to see other ways that work.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to replace string pattern with multi-line text in bash script? brumela Linux - Newbie 6 04-21-2011 06:56 AM
Perl Pattern Matching Question pete1234 Programming 2 08-27-2005 10:26 AM
list files NOT matching a pattern smart_sagittari Linux - Newbie 9 05-20-2005 05:32 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 09:53 AM
Doubt in Pattern matching and vi editor.. suriyamohan Linux - General 2 08-19-2003 05:03 AM


All times are GMT -5. The time now is 11:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration