Link Details

Link 873205 thumbnail
User 965185 avatar

By RafaelZin
via code2learn.com
Published: Nov 05 2012 / 07:45

UNIX doesn't have any real command which helps us to get the number of lines which has records or data in it. But what UNIX offers is to get the number of new lines.
  • 5
  • 1
  • 572
  • 433

Comments

Add your comment
User 411746 avatar

nikolas.lotz replied ago:

0 votes Vote down Vote up Reply

#> cat TEXTFILE | grep -v '^[[:blank:]]*$' | wc -l

User 965185 avatar

RafaelZin replied ago:

0 votes Vote down Vote up Reply

Hi Nikolas, Your command would escape the empty lines, but it will fail in the below scenario: 1.Make a file with 2 records one on each line Example: name.dat Rafael (press Enter) Zin (dont press Enter) 2. After the data in 2nd line dont press enter. As discussed above. 3. Now run your command you will get wrong output.

User 411746 avatar

nikolas.lotz replied ago:

0 votes Vote down Vote up Reply

Nope. After fixing all the typos in your script ('gerp' vs 'grep' and a few missing backticks) it returns the same result.

User 411746 avatar

nikolas.lotz replied ago:

0 votes Vote down Vote up Reply

And another typo: "$nl_coun2" vs "$nl_count2"

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (4)



Voters Against This Link (1)



Spring Integration
Written by: Soby Chacko
Featured Refcardz: Top Refcardz:
  1. Search Patterns
  2. Python
  3. C++
  4. Design Patterns
  5. OO JS
  1. PhoneGap
  2. Spring Integration
  3. Regex
  4. Git
  5. Java