|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
total number of lines in a file
Hi ,
How about find the total number of lines in a file ? How can i do that with the "grep" command ? |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Quote:
You can use wc to find the number of lines. Code:
wc -l < file.txt Using grep you can use Code:
grep -c "." file.txt |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Quote:
Code:
zsh 4.3.4% cat file a b zsh 4.3.4% wc -l file 3 file zsh 4.3.4% grep -c . file 2 may be something like: Code:
zsh 4.3.4% grep -c ^ file 3 and it's not bulletproof either ... Last edited by radoulov; 10-04-2007 at 06:02 AM.. Reason: spelling ... |
|
#4
|
||||
|
||||
|
Quote:
my input file had empty lines or so I thought. It had the ^M characters which resulted into the same result for both wc and grep. ![]() |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
i find it strange that after joining the forum for so long, you still don't know how to do that?
|
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
I suspect homework questions.
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Hi ghostdog, I think i know how to do it. See below! ![]() Code:
wc -l myfile|awk '{print($1)}'` |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Write the total number of rows in multiple files into another file | malaya kumar | UNIX for Dummies Questions & Answers | 4 | 03-30-2012 04:46 AM |
| Select lines in which column have value greater than some percent of total file lines | vaibhavkorde | Shell Programming and Scripting | 6 | 04-21-2011 04:42 AM |
| perl script on how to count the total number of lines of all the files under a directory | adityam | Shell Programming and Scripting | 5 | 07-07-2010 04:36 AM |
| Appending line number to each line and getting total number of lines | chiru_h | Shell Programming and Scripting | 2 | 03-25-2008 10:19 AM |
| total number of lines | mahabunta | Shell Programming and Scripting | 4 | 01-31-2007 04:11 AM |
|
|