I have say file A.txt, B.txt, C.text in a folder. Each of the text file contain few entries. How to count how many entries in each text file has? and also want to extract to a list with first column as name of text file and second column as no. of entries in corresponding file. Thanks
Asked
Active
Viewed 1,414 times
1 Answers
0
By "entries", do you mean "lines"? If so, here is a very basic and quick solution in bash:
files=(A.txt B.txt C.txt)
echo -e "File\tCount"
for i in "${files[@]}"
do
ret=$(cat $i | wc -l)
echo -e "$i\t$ret"
done
Here is the output:
File Count
A.txt 2
B.txt 1
C.txt 1
If you make this into a script, you will probably want to get the list of files as a parameter.

Saulo Silva
- 1,219
- 1
- 20
- 37