![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
#! /bin/ksh
while read file
do
rej=${file##${file%???}}
if [ "$rej" = "Rej" ] ; then
echo "Remove ${file%???}main"
fi ;
done < input.txt
|
|
#3
|
|||
|
|||
|
hi
wht does this code do? rej=${file##${file%???}} thanks swapneel |
|
#4
|
||||
|
||||
|
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.
|
||||
| Google The UNIX and Linux Forums |