0

I need to get the files in which it should contain more than more then 1 lines in it.

eg: file1.txt

756  H#001263  2869  1035  PUR  420200.00

756  H#001263  2866  1023  PUR  157500.00

file2.txt

756  S#001263  2869  7777  MCH  420200.00

file3.txt

(null file)

Expected output ( This should return only the file which has more than 1 lines in it )

file1.txt
anubhava
  • 761,203
  • 64
  • 569
  • 643
user2260984
  • 13
  • 1
  • 4

3 Answers3

1

You can use this for loop to determine that:

for i in *.txt; do [ $(wc -l < "$i") -gt 1 ] && echo "$i"; done
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

How about this?

wc -l *.txt | awk '{if ($1 > 1) print}'

the wc command gives an extra line about the total, if you don't want it, add

| sed -e '/total/d'

at the end.

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
0

In case you know the max size of files having only 1 line, you can use the -size option of the find command, as below:

find . -size +37c
Foo Bar
  • 56
  • 5