LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Closed Thread
  Search this Thread
Old 10-08-2012, 12:21 AM   #1
NickPats
Member
 
Registered: Oct 2012
Posts: 43

Rep: Reputation: Disabled
reading file


Actually i want to use the files in current directory to do wc on each file. I tried wc -wl * . But it prints out the subdirectories and files too. So i want to use for loop . but havent used it before. so if someone can help me with that. how can i read files from current working directory in for loop.?
-Thanks
 
Old 10-08-2012, 06:51 AM   #2
rambolinuxbuddy
LQ Newbie
 
Registered: Sep 2012
Posts: 16

Rep: Reputation: Disabled
exactly What do you want to do?

can you just explain it properly?
 
Old 10-08-2012, 07:06 AM   #3
rambolinuxbuddy
LQ Newbie
 
Registered: Sep 2012
Posts: 16

Rep: Reputation: Disabled
I guess following command will do you work:-

Terminal$ wc -wl *.*

hope it helps you.
 
Old 10-08-2012, 07:54 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
That will only work with files that have file extensions.
I recommend to use find for this problem
Code:
find . -type f -maxdepth 1 -exec wc -l '{}' \;
Short explanation: -type f makes find to only look for files and not directories, -maxdepth 1 prevents to search in subdirectories, the -exec option specifies which command to run when an appropriate file is found.
For more info about the find command have a look at
Code:
man find

Last edited by TobiSGD; 10-08-2012 at 11:09 AM. Reason: fixed code-tags
 
2 members found this post helpful.
Old 10-08-2012, 02:59 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate. Please, follow discussion here: http://www.linuxquestions.org/questi...les-4175431040
 
  


Closed Thread


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
Microsoft Visual C++, Reading from File, Reading an XFile not heirarchy Soulkeeper1987 Programming 1 07-01-2012 05:09 PM
reading and writing to pipes, file descriptors, and file streams cmartin0 Programming 1 02-13-2012 04:03 AM
Reading ext3 file system on Mac and overriding file permission moravveji Other *NIX 6 09-12-2011 03:25 AM
[SOLVED] Reading in a file in C, after file read null terminator at strings end gone josip76 Programming 2 05-14-2010 01:44 AM
awk: fatal:cannot open file for reading (no such file or Directory) in Linux sangati vishwanath Linux - Software 4 07-06-2005 01:59 AM


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

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