i want to delete a file based on existing file in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting i want to delete a file based on existing file in a directory
# 1  
Old 04-11-2006
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  
Old 04-11-2006
Code:
#! /bin/ksh

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

        fi ;
done < input.txt

# 3  
Old 04-11-2006
hi

wht does this code do?

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

thanks
swapneel
# 4  
Old 04-11-2006
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.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create file and file content based existing information?

Hi Gurus, I am SQL developer and new unix user. I need to create some file and file content based on information in two files. I have one file contains basic information below file1 and another exception file file2. the rule is if "zone' and "cd" in file1 exists in file2, then file name is... (13 Replies)
Discussion started by: Torhong
13 Replies

2. UNIX for Dummies Questions & Answers

No such file or directory for existing executable

Hi, I have a very puzzling problem. I have a binary file, it is executable but it says "No such file or directory" when I try to run it : root@debian:~# ls -l bmcfwul -rwxr-xr-t 1 root root 762808 Mar 11 2010 bmcfwul root@debian:~# ./bmcfwul -su: ./bmcfwul: No such file or directory... (9 Replies)
Discussion started by: chebarbudo
9 Replies

3. Shell Programming and Scripting

Need to delete large set of files (i.e) close to 100K from a directory based on the input file

Hi all, I need a script to delete a large set of files from a directory under / based on an input file and want to redirect errors into separate file. I have already prepared a list of files in the input file. Kndly help me. Thanks, Prash (36 Replies)
Discussion started by: prash358
36 Replies

4. Shell Programming and Scripting

generate a file from existing file based on some rule

Hi guys, i have a file in below format.let me explain first what i am trying to do . i am making a file from this file , will rearrange these columns, then i will run several command(start/stop mentioned in this file) on unix environment. my requirements : 1. i have 27 servers , on each server... (4 Replies)
Discussion started by: deepakiniimt
4 Replies

5. Shell Programming and Scripting

Creating a new file based on existing file

Hello Guys , I need an another help regarding the below problem. I want to create a new file based on the existing file ,where two columns will be changed according to user input .(say column 4 and column 5) Please let me know how to proceed with Thanks (3 Replies)
Discussion started by: Pratik4891
3 Replies

6. Shell Programming and Scripting

How to delete already existing data in a file using perl? Pls help me!!

Dear Friends, I need urgent help from u.. I have two files,file1 & file 2.. file1 have a existing data of file2.So i want to delete those existing datas from file1 (which contain the data from file1) My file1 like this rs39348 1 1045729 A G 0.1791 0.2054 0.84 ... (3 Replies)
Discussion started by: sureshraj
3 Replies

7. Shell Programming and Scripting

Delete block of text in one file based on list in another file

Hi all I currently use the following in shell. #!/bin/sh while read LINE do perl -i -ne "$/ = ''; print if !m'Using archive: ${LINE}'ms;" "datafile" done < "listfile" NOTE the single quote delimiters in the expression. It's highly likely the 'LINE' may very well have characters in it... (3 Replies)
Discussion started by: Festus Hagen
3 Replies

8. Shell Programming and Scripting

Creating a csv file based on Existing file

Hi I am Newbie to Unix.Appreciate Help from forum user would loada b.Csv File(Below example) in /data/m/ directory.Program need to read the b.csc to extract certain column and create a new file /data/d/ directory as csv file with new name. User File Format 1232,samshouston,12345... (3 Replies)
Discussion started by: skywayterrace
3 Replies

9. Shell Programming and Scripting

search file, change existing value based on input (awk help)

I have a file (status.file) of the form: valueA 3450 valueB -20 valueC -340 valueD 48 I am tailing a data.file, and need to search and modify a value in status.file...the tail is: tail -f data.file | awk '{ print $3, ($NF - $(NF-1)) }' which will produce lines that look like this: ... (3 Replies)
Discussion started by: nortonloaf
3 Replies

10. UNIX for Dummies Questions & Answers

delete a file from an existing Solaris tar

How can I delete a file from an existing Solaris tar file ? (not gtar) (2 Replies)
Discussion started by: avnerht
2 Replies
Login or Register to Ask a Question