Deleting files in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting files in awk
# 8  
Old 11-27-2009
In your example you could do: -

Code:
find $DIRLOC -name "$FILEEXT" | xargs -i rm -f {}

However this only addresses the issue of not launching rm as a new process every time you delete a file. So with a large amount of files to delete this will be considerably quicker than using -exec in the find command.

Still an issue is not following sub directories and unintentionally deleting files there. So either only do this in a directory that has no sub directories (and never will have!), or learn about the prune function in the find command. There are plenty of posts here on the subject.

Good luck
# 9  
Old 11-30-2009
Really Thanks steadyonabix

Quote:
Originally Posted by steadyonabix
In your example you could do: -

Code:
find $DIRLOC -name "$FILEEXT" | xargs -i rm -f {}

However this only addresses the issue of not launching rm as a new process every time you delete a file. So with a large amount of files to delete this will be considerably quicker than using -exec in the find command.

Still an issue is not following sub directories and unintentionally deleting files there. So either only do this in a directory that has no sub directories (and never will have!), or learn about the prune function in the find command. There are plenty of posts here on the subject.

Good luck
# 10  
Old 11-30-2009
you can try below..deleting may files at a time :
ls | grep "pattern" | xargs -n 100 rm
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mainain the files after deleting lines with awk

hello I want to delete the lines of many files (e.g. file1, file2, ..., file1111) in my directory (e.g. dir1) that they have the 2nd column grater than a value (e.g. 40) placing them to a different directory (e.g. newdir) and keeping the originals. I wrote the code which is functional awk '{... (3 Replies)
Discussion started by: phaethon
3 Replies

2. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

3. Shell Programming and Scripting

How to use awk for deleting columns?

Hi folks, How awk 'll help to do this file contains bunch of insert statement like below remove fourth column from all statement put it in new file INSERT INTO `tbl_medicalquestions` VALUES (1,'Is anyone waiting for an operation, post operative check up, any other hospital treatment or... (12 Replies)
Discussion started by: ashutoshverma
12 Replies

4. Shell Programming and Scripting

Deleting column using awk

How Can we delete a range of coloumns using awk? (or any other method is fine) If we have a file which has about 200 coloumns. I need to delete a particular range lets say for eg from $6 to $119 Can we do this using cut, if yes the cut command would also be helpful. many thanks in... (4 Replies)
Discussion started by: Sri3001
4 Replies

5. Shell Programming and Scripting

AIX system.... deleting files in remote directory after retrieving files

Hi Friends, I am new to this , I am working on AIX system and my scenario is to retrive the files from remote system and remove the files from the remote system after retreving files. I can able to retrieve the files but Can't remove files in remote system. Please check my code and help me out... (3 Replies)
Discussion started by: vinayparakala
3 Replies

6. Shell Programming and Scripting

Need help comparing two files and deleting some things in those files!

So I have two files: File1 pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2 pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2 ref4948 1.1 treehouse.txt 1.6 ref8573 1.5 ref3284 1.4 ref5838... (24 Replies)
Discussion started by: linuxkid
24 Replies

7. Shell Programming and Scripting

Deleting keys and values-Awk

key pair is 1st and 6th column ex:a20 : p10 or a20 : p11 For every key pair if the vlaue(4th column) is the same then delete all the lines who has keypair and the value ex: a20 : p10 has value 1 only then delete those but a20 : p11 has different values 1,2 and 3 and keep those. input a20 ... (8 Replies)
Discussion started by: ruby_sgp
8 Replies

8. Shell Programming and Scripting

Deleting every 3rd field using awk

I have a file whose format is like the following 350,2,16.2,195,2,8.0 every 3rd column of this file should be deleted. How can i achieve this tried with the following iostat -D -l 2 | /usr/xpg4/bin/awk ' NR>2 { for (i=0;i<=NF;i++)if(i%3==0)$i=""};' but no luck (3 Replies)
Discussion started by: achak01
3 Replies

9. Shell Programming and Scripting

printing and deleting using awk

I am trying to print and delete at the same time 0KB files... using following command a-> find . -type f | xargs ls -l | awk '{ if($5 == 0) {print $0;}}' | xargs rm $0 but am not successful. Can somebody tell me how to do this ... same time I need files to be printed as well deleted later. ... (4 Replies)
Discussion started by: vivek.gkp
4 Replies

10. Shell Programming and Scripting

deleting lines using awk-best way?

Hi all....I'm using awk to validate a csv file, but now I've been told to delete any invalid lines from the file.. Im not sure what the best way to do this is? Would it be to create a temp file say "csv_temp.tmp" file and print all the valid records to that temp file. Then delete the old file... (3 Replies)
Discussion started by: satnamx
3 Replies
Login or Register to Ask a Question