Count lines from multiple files (3)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count lines from multiple files (3)
# 1  
Old 12-12-2012
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:

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

# 2  
Old 12-12-2012
Hi Aviv,
Code:
wc -l files

will also give you total line if more than one FILE is specified.
example :
Code:
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
Code:
wc -l file1 file2 file3 file4  | tail -1 | awk '{ print $1 ; }'

This User Gave Thanks to mukulverma2408 For This Post:
# 3  
Old 12-12-2012
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...
# 4  
Old 12-12-2012
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.
This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script count lines and sum numbers from multiple files

I want to count the number of lines, I need this result be a number, and sum the last numeric column, I had done to make this one at time, but I need to make this for a crontab, so, it has to be an script, here is my lines: It counts the number of lines: egrep -i String file_name_201611* |... (5 Replies)
Discussion started by: Elly
5 Replies

2. Shell Programming and Scripting

awk joining multiple lines based on field count

Hi Folks, I have a file with fields as follows which has last field in multiple lines. I would like to combine a line which has three fields with single field line for as shown in expected output. Please help. INPUT hname01 windows appnamec1eda_p1, ... (5 Replies)
Discussion started by: shunya
5 Replies

3. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

4. Shell Programming and Scripting

Count files between multiple directories

Hi All, Everyday we will receive 33 files in our source directory(/prd/pk) with the current date. Once our jobs are completed all the 33 files immediately will be moved to backup folder (/prd/pk/backup). Now, I need to check between source file directory (/prd/pdk) and backup file directory... (3 Replies)
Discussion started by: suresh_target
3 Replies

5. Shell Programming and Scripting

Multiple pattern matching using awk and getting count of lines

Hi , I have a file which has multiple rows of data, i want to match the pattern for two columns and if both conditions satisfied i have to add the counter by 1 and finally print the count value. How to proceed... I tried in this way... awk -F, 'BEGIN {cnt = 0} {if $6 == "VLY278" &&... (6 Replies)
Discussion started by: aemunathan
6 Replies

6. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

7. Shell Programming and Scripting

Trying to do a count on multiple lines in a file

Guys I am having a problem with being able to do a count of entries in a file. What I am trying to get a count of the total number of members that are listed in the files. So I need to pull the number of the lines after members. I tried using sed but it only seems to count the first... (7 Replies)
Discussion started by: scottzx7rr
7 Replies

8. UNIX for Advanced & Expert Users

grep count across multiple files

I have a number of simulation log files and I want to get a total count of the "PASSED" expression in them. If I use grep -c <files>, grep would give a tally for each file. I just want one number, the total count. How do I do that? (4 Replies)
Discussion started by: CrunchMunch
4 Replies

9. Shell Programming and Scripting

Count files lines in a directory?

Hy! I have some problem. Problem is that i don't now how to solve problem of average lines of files in a directory. I have managed to get number of files in a directory, but i don't know the command to count average lines of these files. I have one "for" loop that goes true whole... (13 Replies)
Discussion started by: davidoff
13 Replies

10. UNIX for Dummies Questions & Answers

trying to count lines in multiple files

Hi there, I need help. I want to run the command: less filename | wc -l But on multiple files in a directory So to get those files I would run ls -ltr | grep filename_2000123 or of course ls -ltr *filename_2000123* But I am having a problem running a loop to get a count of each... (1 Reply)
Discussion started by: llsmr777
1 Replies
Login or Register to Ask a Question