Number of *.txt files which have over n lines?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Number of *.txt files which have over n lines?
# 1  
Old 10-31-2008
Number of *.txt files which have over n lines?

Can you help me please?
I know that
Code:
wc -l *.txt

gives you the number of lines in each file. But how can i count the files that have over n lines?
# 2  
Old 10-31-2008
Hammer & Screwdriver One approach

Note, I did the grep to exclude the total line; perhaps other ways to accomplish this also.

Code:
> wc -l * | grep -v " total"
      0 delete_extra
     18 file01
      3 file01k
      3 file02
      4 file05
      4 file06
      4 file08
      4 file09
      3 file10
      0 file11
      1 file12
      5 file13
      7 file14
      7 file14n
      5 file15
     12 file15_1
      3 file20
     25 file21
      4 file22
     17 file23
      3 file24
      0 pass_var
     10 play_file14
      0 resnum
      0 scsi35
      8 sort_22
> wc -l * | grep -v " total" | awk '$1>10'
     18 file01
     12 file15_1
     25 file21
     17 file23

# 3  
Old 10-31-2008
One way -
[code]
n=42
wc -l *.txt | awk -v n=$n '$1>n' | wc -l
/code]
# 4  
Old 10-31-2008
Hammer & Screwdriver

Without needing the grep, as in my previus example
(to exclude the total line)
Code:
> wc -l * | awk '$2!="total" && $1>10'

# 5  
Old 10-31-2008
Assuming 100 lines.

If you have GNU awk:

Code:
awk 'FNR>100{print FILENAME;nextfile}' *

Otherwise (use nawk or /usr/xpg4/bin/awk on Solaris):

Code:
awk 'FNR>100&&!_[FILENAME]++{print FILENAME}' *

With Perl:

Code:
perl -lne'print $ARGV and close ARGV if $.>100' *


Last edited by radoulov; 10-31-2008 at 11:19 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print number of lines for files in directory, also print number of unique lines

I have a directory of files, I can show the number of lines in each file and order them from lowest to highest with: wc -l *|sort 15263 Image.txt 16401 reference.txt 40459 richtexteditor.txt How can I also print the number of unique lines in each file? 15263 1401 Image.txt 16401... (15 Replies)
Discussion started by: spacegoose
15 Replies

2. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

3. Shell Programming and Scripting

Pasting files with different number of lines

Hi all, I tried to use the paste command to paste two files with different number of lines. e.g. file1 A 1 B 1 C 2 D 2 file2 A 2 B 3 C 4 D 4 E 4 (2 Replies)
Discussion started by: f_o_555
2 Replies

4. UNIX for Dummies Questions & Answers

find lines in file1.txt not found in file2.txt memory problem

I have a diff command that does what I want but when comparing large text/log files, it uses up all the memory I have (sometimes over 8gig of memory) diff file1.txt file2.txt | grep '^<'| awk '{$1="";print $0}' | sed 's/^ *//' Is there a better more efficient way to find the lines in one file... (5 Replies)
Discussion started by: raptor25
5 Replies

5. Shell Programming and Scripting

merging two .txt files by alternating x lines from file 1 and y lines from file2

Hi everyone, I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines). Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
Discussion started by: ink_LE
6 Replies

6. Shell Programming and Scripting

sed to cp lines x->y from 1.txt into lines a->b in file2.txt

I have one base file, and multiple target files-- each have uniform line structure so no need to use grep to find things-- can just define sections by line number. My question is quite simple-- can I use sed to copy a defined block of lines (say lines 5-10) from filename1.txt to overwrite an... (3 Replies)
Discussion started by: czar21
3 Replies

7. Shell Programming and Scripting

How to remove certain lines in multiple txt files?

Hi , I have this type of files:- BGH.28OCT2008.00000001.433155.001 BGH.28OCT2008.00000002.1552361.001 BGH.28OCT2008.00000003.1438355.001 BGH.28OCT2008.00000004.1562602.001 Inside them contains the below: 5Discounts 6P150 - Max Total Usage RM150|-221.00 P150 EPP - Talktime RM150... (5 Replies)
Discussion started by: olloong
5 Replies

8. Shell Programming and Scripting

Restore files by lines number!

Hello every 1 Happy new year ;) I have a problem when i've tried to write my shell scripts.. this what i've done Actually, i would like to restore the files that i have deleted by line number for example : 1 : filename1 2: filename2 3: filename3 then i can restore them by... (8 Replies)
Discussion started by: John_Smith
8 Replies

9. Shell Programming and Scripting

need help--script to filter specific lines from multiple txt files

Hi folks, - I have 800 txt files - those files are cisco router configs router1.txt router2.txt ... router800.txt I want to accomplish the following: - I want to have a seperate file with all the filenames that I want to process - I want a script that goes trough all those... (7 Replies)
Discussion started by: I-1
7 Replies

10. Shell Programming and Scripting

Extracting 10 digit number from txt files

Hi, Was wondering if you could give me an example of extracting a 10 digit number from 5 txt files using a regular expression (the number is always different ) and storing the numbers in variables Thanks C19 (9 Replies)
Discussion started by: c19h28O2
9 Replies
Login or Register to Ask a Question