Search for text files with less than 2000 lines and delete them

I have many single column text files.

Some text file has 2,000 lines (consisting of numbers), and some others have less than 2,000 lines (also consisting of numbers only).

I want to remove all textures with less than 2000 lines in them.

ADDITIONAL INFORMATION

Files shorter than 2000 lines are not empty, they all have line breaks up to line 2000. In addition, my files have several complex names: Nameofpop_chr1_window1.txt

I tried using awk to first count the lines of my text file, but due to the presence of line breaks for each file, I get the same result, 2000 for each file.

awk 'END { print NR }' Nameofpop_chr1_window1.txt

Thanks in advance.

+3
source share
3 answers

awk :

awk 'NF{i++} END { print i }' Nameofpop_chr1_window1.txt

awk ,

awk '/^[[:digit:]]+$/ {i++} END { print i }' Nameofpop_chr1_window1.txt

2000 , awk:

for f in f*; do
    [[ -n $(awk '/^[[:digit:]]+$/{i++} END {if (i<2000) print FILENAME}' "$f") ]] && rm "$f"
done
+4

expr $(cat filename|sort|uniq|wc -l) - 1 cat filename|grep -v '^$'|wc -l, ,

0

You can use bash:

for f in $files; do
    n=0
    while read line; do
        [[ -n $line ]] && ((n++))
    done < $f
    [ $n -lt 2000 ] && rm $f
done
0
source

All Articles