Count the number of lines in a file with one condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count the number of lines in a file with one condition
# 1  
Old 02-10-2010
Count the number of lines in a file with one condition

Hi Everyone,
1.txt
Code:
Mon 08 Feb 2010 12:30:44 AM MYT;1265560244;e164:0000116047275464;T;Central;0;
Mon 08 Feb 2010 12:30:46 AM MYT;1265560246;e164:0000116047275464;T;Central;0;
Mon 08 Feb 2010 12:30:48 AM MYT;1265560248;e164:0000116047275464;T;Central;0;
Mon 08 Feb 2010 12:30:50 AM MYT;1265560250;e164:0000116047275464;T;Central;0;
Mon 08 Feb 2010 12:30:54 AM MYT;1265560254;e164:0000116047275464;T;Central;0;
Mon 08 Feb 2010 12:36:36 AM MYT;1265560596;e164:0000116062743311;T;Central;0;
Mon 08 Feb 2010 12:40:15 AM MYT;1265560818;e164:0000116047277997;T;Central;2;
Mon 08 Feb 2010 12:41:07 AM MYT;1265560882;e164:0000116047277997;T;Central;14;
Mon 08 Feb 2010 12:44:45 AM MYT;1265561085;e164:0000116096386127;T;Central;0;
Mon 08 Feb 2010 12:47:29 AM MYT;1265561252;e164:0000116069037982;T;Central;3;
Mon 08 Feb 2010 12:47:38 AM MYT;1265561258;e164:0000116069038211;T;Central;0;

i know "wc -l 1.txt" can get the total lines = 11. but if i want to count only the field 6 is greater than 0, means the output should be = 3.
i can think to use for loop. but is any simple way, like awk into one line code?
please advice. thanks

---------- Post updated at 11:20 PM ---------- Previous update was at 11:04 PM ----------

got already
Code:
awk -F';' '$6>0' 1.txt | wc -l


Last edited by jimmy_y; 02-10-2010 at 12:19 AM..
# 2  
Old 02-10-2010
Code:
 awk -F\; '$6>0{c++}END{print c}'  infile

wc not required Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print lines based on line number and specified condition

Hi, I have a file like below. 1,2,3,4,5,6,7,8,9I would like to print or copied to a file based of line count in perl If I gave a condition 1 to 3 then it should iterate over above file and print 1 to 3 and then again 1 to 3 etc. output should be 1,2,3 4,5,6 7,8,9 (10 Replies)
Discussion started by: Anjan1
10 Replies

2. Shell Programming and Scripting

Want to count the number of lines after the first line

hi, How can i count the number of lines after the first line in a flat file in unix? Say i have a flat file with a header like: Student Name Student ID .... Tnx (7 Replies)
Discussion started by: reignangel2003
7 Replies

3. UNIX for Advanced & Expert Users

Count number of lines between a pattern in a large file

1000CUS E Y4NYRETAIL 10010004HELIOPOLIS 110000500022360591000056XX EG 1101DEBY XXAD ZSSKY TSSROS 1102HANYNNYY@HOTMAIL.COM 210030/05/201301/06/2013AED 3100 OPE 3100 CLO 3100 The 1000CUS E Y NYCORPORATE 10010004HELIOPOLIS 110000500025270504550203XX EG 1101XXXQ FOR CTING AND... (1 Reply)
Discussion started by: john2022
1 Replies

4. Shell Programming and Scripting

Count number of free lines in a text file

Hi Everybody I want to write a script to count the number of lines in a file that don't ahve any thing on it, the free lines, i try to do it with fgrep "" which means to grep on the spaces but it does not work. help me please? (3 Replies)
Discussion started by: hard_revenge
3 Replies

5. UNIX for Dummies Questions & Answers

Count Number Of lines in text files and append values to beginning of file

Hello, I have 50 text files in a directory called "AllFiles" I want to make a program that will go inside of the "AllFiles" Directory and count the number of lines in each individual text file. Then, the program will calculate how many more lines there are over 400 in each text file and... (7 Replies)
Discussion started by: motoxeryz125
7 Replies

6. Shell Programming and Scripting

count number of lines between two tag

Hi I have a big xml file of having many data </Data> </Node> <Node> List <abc>3932590983 3396003964 3355713230</abc> </Data> </Node> </Data> </Node> <abc>3932590983 3396003964</abc>I want to count the lines present betweem tag starting with abc and ending with abc so o/p will be... (8 Replies)
Discussion started by: aaysa123
8 Replies

7. Shell Programming and Scripting

count the number of lines that start with the number

I have a file with contents similar to this. abcd 1234 4567 7666 jdjdjd 89289 9382 92 jksdj 9823 298 I want to write a shell script which count the number of lines that start with the number (disregard the lines starting with alphabets) (1 Reply)
Discussion started by: grajp002
1 Replies

8. UNIX for Dummies Questions & Answers

Count of Number of Lines in a File

Dear Members, I want to count the number of lines in a file; for that i am using the following command : FILE_LINE_COUNT=`wc -l $INT_IN/$RAW_FILE_NAME` if i do an echo on FILE_LINE_COUNT then i get 241 /home/data/testfile.txt I don't want the directory path to be displayed. Variable... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

9. Programming

to count the number of commented lines in a file

can someone guide me how to have a C pgm to count the number of commented lines? (3 Replies)
Discussion started by: naan
3 Replies

10. Shell Programming and Scripting

Count number of lines in Binary file

Hi Friends Please help me out to count number of lines in binary file. It gives some wrong(less) using wc -l. Is there any other way to count lines of binary file. Thanks. (3 Replies)
Discussion started by: vanand420
3 Replies
Login or Register to Ask a Question