Computer Hope
Software => BSD, Linux, and Unix => Topic started by: arz_razi 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
-
You're nearly there with wc and awk. Just throw tail into the mix and its done.
wc -l *.txt | awk '{print $1}' | tail -1
-
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
-
There are 2 ways to solve this.
Throw in another command
grep '^Name :' *.txt | wc -l| awk '{print $1}'
Or do the whole thing in awk
awk 'BEGIN {total = 0}($1 == "Name"){total++} END {print total}' *.txt