Removing files based on name and content


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Removing files based on name and content
# 1  
Old 01-10-2012
Removing files based on name and content

Consider i have 2 directories a1 and a2.
under a1, i have below files
Code:
test1
test2
test3.

Under a2,i have below files.
Code:
test1
test2
test3
test4
test5

My requirement is i will pass the directory names(2 parameters) and directory in which files needs to be removed.(3rd parameter)
a)first scenario is, we need to remove the test1 test2 and test3 files from a2 since those are in a1(just checking the file name)
b)second scenario,Remove test1 test2 and test3 from a2 ,if the actual contents are also same.

Thanks

Last edited by pandeesh; 01-10-2012 at 01:17 AM..
# 2  
Old 01-10-2012
why you are not using code tags ?
# 3  
Old 01-10-2012
Quote:
Originally Posted by itkamaraj
why you are not using code tags ?
I thought that i din't post any script .Thats why i haven't used.Now i understand i need to use. Thanks
# 4  
Old 01-10-2012
Remove test1 test2 and test3 from a2 ,if the actual contents are also same

Same in a2 itself ?

means..

test1 = test2 = test3 ?
# 5  
Old 01-10-2012
Quote:
Originally Posted by itkamaraj
Remove test1 test2 and test3 from a2 ,if the actual contents are also same

Same in a2 itself ?

means..

test1 = test2 = test3 ?
No.Remove test1,test2 and test3 from a2 if their contents are similar to test1,test2 and test3 in a1.
I hope u get the requirement.
# 6  
Old 01-10-2012
a)
Code:
 
cd a1
for i in *; do [ -f a2/$i ] && echo "rm ../b/$i" ; done

b)
Code:
 
 cd a1
 for i in *; do [ -f a2/$i ] && diff $i a2/$i > /dev/null && echo "rm a2/$i" ; done

This User Gave Thanks to itkamaraj For This Post:
# 7  
Old 01-10-2012
can you explain this part:
Code:
"rm ../b/$i"

what does that /b/ stahbd for?

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split content based on keywords

I need to split the file contents with multiple rows based on patterns Sample: Input: ABC101testXYZ102UKMNO1092testing ABC999testKMNValid Output: ABC101test XYZ102U KMN1092testing ABC999test KMNValid In this ABC , XYZ and KMN are patterns (6 Replies)
Discussion started by: Jairaj
6 Replies

2. Shell Programming and Scripting

Split content based on keywords

I need to split the file contents with multiple rows based on patterns Sample: Input: ABC101testXYZ102UKMNO1092testing ABC999testKMNValid Output: ABC101test XYZ102U KMN1092testing ABC999test KMNValid In this ABC , XYZ and KMN are patterns Continue here./mod] Please read forum... (1 Reply)
Discussion started by: Jairaj
1 Replies

3. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts my scenario is as follows... I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims". All files are getting... (17 Replies)
Discussion started by: phani333
17 Replies

4. Shell Programming and Scripting

List the files after sorting based on file content

Hi, I have two pipe separated files as below: head -3 file1.txt "HD"|"Nov 11 2016 4:08AM"|"0000000018" "DT"|"240350264"|"56432" "DT"|"240350264"|"56432" head -3 file2.txt "HD"|"Nov 15 2016 2:18AM"|"0000000019" "DT"|"240350264"|"56432" "DT"|"240350264"|"56432" I want to list the... (6 Replies)
Discussion started by: Prasannag87
6 Replies

5. Shell Programming and Scripting

Split a file in more files based on score content

Dear All, I have the following file tabulated: ID distanceTSS score 8434 571269 10 10122 393912 9 7652 6 10 4863 1451 9 8419 39 2 9363 564 21 9333 7714 22 9638 8334 9 1638 1231 11 10701 918 1000 6587 32056 111 What I would like to do is the following, create 100 new files based... (5 Replies)
Discussion started by: paolo.kunder
5 Replies

6. Shell Programming and Scripting

Split the file based on the content

Arun kumar something somehting Enterting in to the line . . . . Some text text Finshing the sentence Some other text . . . . Again something somehting Enterting in to the line . . . . . . Again text text Finshing the sentence (6 Replies)
Discussion started by: arukuku
6 Replies

7. Shell Programming and Scripting

multiplication of two files based on the content of the first column

Hi, This is something that probably it is more difficult to explain than to do. I have two files e.g. FILE1 A15 8.3102E+00 3.2000E-04 A15 8.5688E+00 4.3000E-05 B13 5.1100E-01 1.9960E+00 B16 5.1100E-01 2.3000E-03 B16 8.6770E-01 1.0000E-07 B16 9.8693E-01 3.4000E-05... (4 Replies)
Discussion started by: f_o_555
4 Replies

8. UNIX for Dummies Questions & Answers

Removing lines that are (same in content) based on columns

I have a file which looks like AA BB CC DD EE FF GG HH KK AA BB GG HH KK FF CC DD EE AA BB CC DD EE UU VV XX ZZ AA BB VV XX ZZ UU CC DD EE .... I want the script to give me only one line based on duplicate contents: AA BB CC DD EE FF GG HH KK AA BB CC DD EE UU VV XX ZZ (7 Replies)
Discussion started by: adsforall
7 Replies

9. Shell Programming and Scripting

Searching and Removing File Content

Hi, I am trying to search a character in a file and remove it from that file.... My file looks something like this: test1.txt ckj12300_00|123|var1|10.2 ckj00200_12|444|var2|11.2 ckj00200_14|4556|var3|33.5 c00200_00_000|4558|var4|33.5 ckj00200_14|4553|var5|33.5... (7 Replies)
Discussion started by: rkumar28
7 Replies
Login or Register to Ask a Question