Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Row counts  (Read 4244 times)

0 Members and 1 Guest are viewing this topic.

arz_razi

  • Guest
Row counts
« on: February 04, 2007, 09:14:04 PM »
 I've problem for counting rows of multiple text(.txt) file. How can i use command to get the row count.  
The test files is like this.
      
   txt file1           txt file2
        a,1111          z,999
        b,2222          y,888
        c,3333          x,777
 
I've tried cmd wc -l filename | awk '{print $1}' and the output is  
 
       3  
       3  
       6
 
if cmd like this wc -l filename (without awk), the output,
 
       3 file1
       3 file2
       6 total
 
How can i get only the total value (in above case '6')

Please help me

banjo67xxx

  • Guest
Re: Row counts
« Reply #1 on: February 06, 2007, 01:09:14 PM »
You're nearly there with wc and awk. Just throw tail into the mix and its done.
Code: [Select]
wc -l *.txt | awk '{print $1}' | tail -1

arz_razi

  • Guest
thanks
« Reply #2 on: February 06, 2007, 09:47:44 PM »
thanks..

but how about this one above...

$cat file.txt ... then the output

Name : razi
Acc   : 1111
Name : ana
Acc   : 2222
Name : John
Acc   : 3333

How can i select only the NAME ROW.

The output that i desire is

Name : Razi
Name : Ana
Name : John

Do assist me..thanks




banjo67xxx

  • Guest
Re: Row counts
« Reply #3 on: February 07, 2007, 02:36:00 AM »
There are 2 ways to solve this.

Throw in another command
Code: [Select]
grep '^Name :' *.txt | wc -l| awk '{print $1}'
Or do the whole thing in awk
Code: [Select]
awk 'BEGIN {total = 0}($1 == "Name"){total++} END {print total}' *.txt