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
Based on the permision in the dir can i delete the file arunkumar_mca UNIX for Dummies Questions & Answers 4 01-08-2008 01:59 PM
Creating a csv file based on Existing file skywayterrace Shell Programming and Scripting 3 12-02-2007 09: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 07:02 AM
search file, change existing value based on input (awk help) nortonloaf Shell Programming and Scripting 3 12-06-2006 01:35 AM
delete a file from an existing Solaris tar avnerht UNIX for Dummies Questions & Answers 2 03-20-2002 05:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-10-2006
srivsn srivsn is offline
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
  #2 (permalink)  
Old 04-11-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

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

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

        fi ;
done < input.txt
  #3 (permalink)  
Old 04-11-2006
d_swapneel14 d_swapneel14 is offline
Registered User
  
 

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

wht does this code do?

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

thanks
swapneel
  #4 (permalink)  
Old 04-11-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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.
Sponsored Links
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 07: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