user14447697
user14447697

Reputation:

Delete file based on condition

I have a directory that contain text file and the files are used for some calculation and it produces four column files

Like:

0.5000 -0.9650 6.6554 3.4228

when column 2 greater than zero and column 3 less than zero then I want to delete that file from folder. I tried script below:

#!bin/sh
for file in /home/dew/*.txt
    do
    some calulation for producing four column `file1`
    if awk '{print ($2 > 0 && $3 < 0)}' file1 | rm -rf $file
done

But it gives some errors

Upvotes: 2

Views: 454

Answers (1)

anubhava
anubhava

Reputation: 785156

You may use this awk + xargs:

cd /home/dew
awk -v ORS='\0' '$2 > 0 && $3 < 0 {print FILENAME; nextfile}' *.txt | 
xargs -0 rm

Upvotes: 2

Related Questions