Count lines from multiple files (3)

Hey everyone,

I've to count lines from string of files names then to show sum output of lines.
for example:
read x = F1 F2 F3
F1 = 12 lines
F2 = 14 lines
F3 = 10 lines

= 36

what I did is:


read x
echo $x >|temp
for x in $(cat temp)
do
wc -l < $x
done >| temp2

Hi Aviv,

wc -l files

will also give you total line if more than one FILE is specified.
example :

wc -l file1 file2 file3 file4
 13 file1
  9 file2
  3 file3
  9 file4
 34 total

then u can try below code to get the total number of lines

wc -l file1 file2 file3 file4  | tail -1 | awk '{ print $1 ; }'
1 Like

Thanks for your answer,
I tried to use your code but it's not working... you can show me another code without the "awk" command?

sorry it's working but I've to use another command...

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.

1 Like