The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Based on the permision in the dir can i delete the file arunkumar_mca UNIX for Dummies Questions & Answers 4 01-08-2008 10:59 AM
Creating a csv file based on Existing file skywayterrace Shell Programming and Scripting 3 12-02-2007 06:19 AM
Need to delete the files based on the time stamp of the file samudha UNIX for Dummies Questions & Answers 2 06-20-2007 04:02 AM
search file, change existing value based on input (awk help) nortonloaf Shell Programming and Scripting 3 12-05-2006 10:35 PM
delete a file from an existing Solaris tar avnerht UNIX for Dummies Questions & Answers 2 03-20-2002 02:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-10-2006
Registered User
 

Join Date: Dec 2005
Posts: 32
i want to delete a file based on existing file in a directory

hi

i am having four files in a directory.like

1)sampleRej
2)exampleRej
3)samplemain
4)examplemain

my requirement is i have to search for the rejected files (sampleRej,exampleRej) in a directory.if these files in that directory then i have to delete the main files (samplemain,examplemain)

directoryname:: abc

please help me.

thanks
Reply With Quote
Forum Sponsor
  #2  
Old 04-10-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Code:
#! /bin/ksh

while read file
do
        rej=${file##${file%???}}
        if [ "$rej" = "Rej" ] ; then
                echo "Remove ${file%???}main"

        fi ;
done < input.txt
Reply With Quote
  #3  
Old 04-11-2006
Registered User
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
hi

wht does this code do?

rej=${file##${file%???}}

thanks
swapneel
Reply With Quote
  #4  
Old 04-11-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
man sh -> sub topic "Parameter Expansion".

Code:
       ${parameter#word}
       ${parameter##word}
              The  word  is  expanded to produce a pattern just as in pathname
              expansion.  If the pattern matches the beginning of the value of
              parameter,  then  the  result  of  the expansion is the expanded
              value of parameter with the shortest matching pattern (the ``#''
              case) or the longest matching pattern (the ``##'' case) deleted.
              If parameter is @ or *, the pattern removal operation is applied
              to  each  positional parameter in turn, and the expansion is the
              resultant list.  If parameter is an array  variable  subscripted
              with  @  or  *, the pattern removal operation is applied to each
              member of the array in turn, and the expansion is the  resultant
              list.

       ${parameter%word}
       ${parameter%%word}
              The  word  is  expanded to produce a pattern just as in pathname
              expansion.  If the pattern matches a  trailing  portion  of  the
              expanded value of parameter, then the result of the expansion is
              the expanded value of parameter with the shortest matching  pat-
              tern  (the  ``%''  case)  or  the  longest matching pattern (the
              ``%%'' case) deleted.  If parameter  is  @  or  *,  the  pattern
              removal  operation  is  applied  to each positional parameter in
              turn, and the expansion is the resultant list.  If parameter  is
              an  array  variable subscripted with @ or *, the pattern removal
              operation is applied to each member of the array  in  turn,  and
              the expansion is the resultant list.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0