Finding text files with less than 2000 rows and deleting them

JM88

I have A LOT of text files, with just one column.

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

I want to delete all the textiles with less than 2000 lines in them.

EXTRA INFO

The files that have less than 2000 lines, are not empty they all have line breaks till row 2000. Plus my files have some complicated names like: Nameofpop_chr1_window1.txt

I tried using awk to first count the lines of my text file, but because there are line breaks for every file I get the same result, 2000 for every file.

awk 'END { print NR }' Nameofpop_chr1_window1.txt

Thanks in advance.

anubhava

You can use this awk to count non-empty lines:

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

OR this awk to count only those lines that have only numbers

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

To delete all files with less than 2000 lines with numbers use this awk:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Finding unique numbers from sorted array in less than O(n)

From Dev

Finding "local maximas" but ignore value less than 20% of highest one

From Dev

Finding number of elements in one vector that are less than an element in another vector

From Dev

Select rows where day is less than today

From Dev

Finding all Prime Numbers less than an input

From Dev

MYSQL SELECT only if rows are less than 5

From Dev

Stop tracking files in git (without deleting them)

From Dev

Finding a calculated ratios less than the average (SQL)

From Dev

Finding a "complete" convex hull in less than O(n^2)

From Dev

How to print out specific rows/lines in a text file based on a condition (greater than or less than)

From Dev

Deleting files after creating them

From Dev

Deleting files with "certain" words in them

From Dev

Finding the number of elements less than or equal to k in a multiset

From Dev

How to count rows in text files and store them in a single file?

From Dev

Optimal way for finding index of 'greatest value less than' in Numpy array

From Dev

gzip all files without deleting them

From Dev

Finding duplicate files and replace them with symlinks

From Dev

Gracefully deleting files older than 30 days

From Dev

Finding and deleting files with a specific date

From Dev

How to remove a row if the difference between two columns is less than 2000

From Dev

Deleting rows with less of 7 columns and with an empty second column

From Dev

Overwriting files vs deleting them?

From Dev

compute sum up each 2 rows and replace them with another value if the sum is less than a specific value

From Dev

Finding differences between two rows and adding them

From Dev

Deleting rows in TableViewController after Swiping them in TableViewCell

From Dev

How to count rows in text files and store them in a single file?

From Dev

Sed deleting content between 2 patterns if they are less than n lines

From Dev

Why does finding files with regular expressions put the files in a different format than just listing them?

From Dev

Deleting a Row in Excel if Value is less than X

Related Related

  1. 1

    Finding unique numbers from sorted array in less than O(n)

  2. 2

    Finding "local maximas" but ignore value less than 20% of highest one

  3. 3

    Finding number of elements in one vector that are less than an element in another vector

  4. 4

    Select rows where day is less than today

  5. 5

    Finding all Prime Numbers less than an input

  6. 6

    MYSQL SELECT only if rows are less than 5

  7. 7

    Stop tracking files in git (without deleting them)

  8. 8

    Finding a calculated ratios less than the average (SQL)

  9. 9

    Finding a "complete" convex hull in less than O(n^2)

  10. 10

    How to print out specific rows/lines in a text file based on a condition (greater than or less than)

  11. 11

    Deleting files after creating them

  12. 12

    Deleting files with "certain" words in them

  13. 13

    Finding the number of elements less than or equal to k in a multiset

  14. 14

    How to count rows in text files and store them in a single file?

  15. 15

    Optimal way for finding index of 'greatest value less than' in Numpy array

  16. 16

    gzip all files without deleting them

  17. 17

    Finding duplicate files and replace them with symlinks

  18. 18

    Gracefully deleting files older than 30 days

  19. 19

    Finding and deleting files with a specific date

  20. 20

    How to remove a row if the difference between two columns is less than 2000

  21. 21

    Deleting rows with less of 7 columns and with an empty second column

  22. 22

    Overwriting files vs deleting them?

  23. 23

    compute sum up each 2 rows and replace them with another value if the sum is less than a specific value

  24. 24

    Finding differences between two rows and adding them

  25. 25

    Deleting rows in TableViewController after Swiping them in TableViewCell

  26. 26

    How to count rows in text files and store them in a single file?

  27. 27

    Sed deleting content between 2 patterns if they are less than n lines

  28. 28

    Why does finding files with regular expressions put the files in a different format than just listing them?

  29. 29

    Deleting a Row in Excel if Value is less than X

HotTag

Archive