LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   reading file (https://www.linuxquestions.org/questions/linux-newbie-8/reading-file-4175431043/)

NickPats 10-07-2012 11:21 PM

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

rambolinuxbuddy 10-08-2012 05:51 AM

exactly What do you want to do?

can you just explain it properly?

rambolinuxbuddy 10-08-2012 06:06 AM

I guess following command will do you work:-

Terminal$ wc -wl *.*

hope it helps you.

TobiSGD 10-08-2012 06:54 AM

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

colucix 10-08-2012 01:59 PM

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


All times are GMT -5. The time now is 12:00 PM.