File content deletion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File content deletion
# 1  
Old 02-15-2010
File content deletion

Hi Everyone,

There are certain files under a folder 'ABC' and the entries for these files are there in another file(fname) under a different folder 'XYZ'. I want to compare the folder contents(ABC) with
the file(fname) contents and delete the mismatching / non-existing ones from the file, fname.

thanks in advance
# 2  
Old 02-15-2010
Something like this:
Code:
> ls -1
abc
bar
baz
def
foo
> cat ../files.txt
abc
def
bar
> ls | grep -vf ../files.txt | xargs rm
> ls -1
abc
bar
def

# 3  
Old 02-15-2010
Hi pludi,

This deletes the files from the folder after comparison.

to be more specific about my problem, if

abc
bar
baz

are the files under 'ABC', the same entries(only entries) exist within files.txt under XYZ. In case, files.txt under XYZ has additional entries

def
foo

apart from abc, bar and baz, then after comparison, only the additional two entries:def and foo need to be removed from files.txt. The contents of 'ABC' should remain untouched.

Thank you
# 4  
Old 02-15-2010
Am I being thick or is this the same effect as copying the list of files in directory ABC to the file "fname" ?
# 5  
Old 02-15-2010
hi methyl,

the files under ABC get added to fname. entries from fname get deleted after the files get processed and files under ABC get renamed. So while fname gets emptied after a while, entries might pile up if a mismatch happens. this shouldn't occur. hence the reason for comparison and deletion

any suggestions welcome
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 remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

2. Shell Programming and Scripting

want file to regenerate after deletion

I looked into the sticky bit, but I think, if possible, that I would prefer to have the file recreate itself after deletion. The file is several directories deep, and from time to time the top level directory will be trashed. I need the file to recreate after this. Is it possible to perhaps... (13 Replies)
Discussion started by: glev2005
13 Replies

3. Shell Programming and Scripting

file and directory deletion script

I saw many post about this but could not find a specific answer to this question. i have the following code find . -depth -name "$FILEEXT" -ctime -30 -exec rm {} \; when i type ./deletefiles.sh *.txt for example, it will find all the txt files less than 30 days old and delete them. my... (9 Replies)
Discussion started by: new2learn09
9 Replies

4. Shell Programming and Scripting

Deletion of lines in a text file

Hi Everyone, Please help me with this. I have gone through many posts here but couldn't find what I wanted. I have a file with 79000+ lines and I want to delete lines in a pattern. I want to delete every 141st line in the file, starting from line 2000 till 50000. Please help guys. ... (8 Replies)
Discussion started by: max29583
8 Replies

5. Programming

How to watch for file creation/deletion?

How do I write a C program that will watch a directory for file creation/deletion? Maybe it would receive a signal when someone creates a file? thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies

6. Shell Programming and Scripting

Prompting for file deletion?

I got help in another forum but now I need further help so I figured I'd ask here. I had to write a script to delete certain filenames of certain size. I got this far.. find . -size 110c -name "*testing*" -print | xargs -n 1 rm -i It finds the correct files, but the prompts to delete are all... (2 Replies)
Discussion started by: NycUnxer
2 Replies

7. UNIX for Dummies Questions & Answers

file deletion problem

I am using unix via telnet ssh and i have a problem I was testing the server. I made a directory. Transfered a file from an ftp to it. Opened the file with the vi text editor --This where my problem came..... I tried deleting the file using rm somefile.htm when is typed ls i noticed that... (2 Replies)
Discussion started by: shdwsclan
2 Replies

8. UNIX for Dummies Questions & Answers

large file deletion

OS: Solaris 8 I deleted a large file (around 13 Gigs) from my system. But the output of df -k remains the same. The capacity % is constant. However one strange thing is happening- My available space is decreasing, my used space in increasing (The opposite should happen). This is happening... (2 Replies)
Discussion started by: run_time_error
2 Replies

9. UNIX for Dummies Questions & Answers

Deletion of File in Unix

Hi there guys. I'm quite new in using unix and just recently experienced missing file problem. Someone accidentally or likely intentionally deleted one specific folders that contains important file. Now my question is, can any other user aside from root can do such action? Please help. ... (2 Replies)
Discussion started by: rhomel101
2 Replies

10. Shell Programming and Scripting

File deletion when server restarts

Hi, In a shell script I am makin use of 3 files f1,f2 and f3.txt. When the Unix server is restarted I want to delete all these 3 files if they are existing. ( I suppose I will have to use this command rm /thefilepath/f* but dont know in which script to use.) Anyone knows what can be... (6 Replies)
Discussion started by: k_oops9
6 Replies
Login or Register to Ask a Question