Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-15-2010, 02:12 AM   #1
Registered: Sep 2008
Location: Mumbai, india
Distribution: ubuntu and hp-unix
Posts: 118

Rep: Reputation: 15
count lines and words

How can I display the no. of lines, words and characters for each file in current directory and in sub directory.

wc . * shows errornous result as there are some executable files in that directory.
Old 02-15-2010, 02:34 AM   #2
Simon Bridge
LQ Guru
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Sounds like homework.

You want your operation to skip non-text files - which means you'll need to put it in a script.
What is the difference between files that have words and lines to count and those which do not? Work out how to test for this and write your script accordingly.

The bash command "file" will probably help. You may also discover that all the valid files have some identifier in their name, like .txt
Old 02-15-2010, 02:39 AM   #3
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Can you try this lipun4u,
wc `find . -type f | xargs ls -l | grep -v "^...x" | tr -s " " | cut -d " " -f 9` | more

Last edited by vinaytp; 02-15-2010 at 02:40 AM.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to count occurrences of unique words in a file beeblequix Linux - General 8 06-05-2018 11:16 AM
How would I ignore other lines in a file with non unique words? btacuso Linux - Newbie 1 05-24-2009 09:20 AM
script to count lines kalimat Programming 16 12-15-2008 05:09 AM
Get all lines containing 23 specific words with AWK cgcamal Programming 3 11-05-2008 11:51 AM
how many lines and words (bash) sharapchi Programming 4 12-15-2006 01:45 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:06 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration