LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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


Reply
  Search this Thread
Old 11-19-2018, 12:24 AM   #1
avyadav555
LQ Newbie
 
Registered: Apr 2016
Posts: 20

Rep: Reputation: Disabled
word counting for specific type of files in multiple directory.


hi.... i am using the command (for D in /; do wc -l ${D}/ > ${D%/}Request;done) for word count but the problem is now it read all files in the particular directory .I want to read only .CUD files . Please suggest
NOTE: i have multiple directory, all directory contains .cud and .cur files. here i want data(no of lines) which are in .cud files only

please suggest...!!!!
 
Old 11-19-2018, 01:49 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Code:
for D in /; do wc -l ${D}/ > ${D%/}Request;done
for D in / will process a single file, namely /.
Quote:
Originally Posted by avyadav555 View Post
I want to read only .CUD files . Please suggest
NOTE: i have multiple directory, all directory contains .cud and .cur files. here i want data(no of lines) which are in .cud files only
You need to generate the list of all your CUD files, then run wc on them. E.g.
Code:
wc -l $(find / -name ‘*.CUD’)
This will fail if there are too many CUD files. A better way is building the wc command into find, for example
Code:
find / -name ‘*.CUD’ -exec wc -l {} +
The strange string {} indicates the file that was found.
 
Old 11-19-2018, 07:12 AM   #3
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by avyadav555 View Post
hi.... i am using the command (for D in /; do wc -l ${D}/ > ${D%/}Request;done) for word count but the problem is now it read all files in the particular directory .
  • wc -l counts new lines, not words (see switch -w for that purpose)
  • Are you really sure your command is working?? As said by berndbausch this for loop only processes one file, namely "/"...
 
Old 11-19-2018, 07:59 AM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,388

Rep: Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764
It would help if you properly specified your requirement.
From this thread
Quote:
hi used the command ==>> for D in /; do wc -l ${D}/ > ${D%/}Request;done which is working fine . But in each directory there are two file named as .CUD and .CUR , I want to read both files separately . Please suggest
and now in this thread
Quote:
I want to read only .CUD files
Try running this command in the top directory under which are all .CUD files to be interrogated.
Code:
( shopt -s globstar; for f in **/*.CUD; do wc -l "$f"; done )
The parentheses are important, to force the command to run in a subshell.
It is still unclear how you want the output; individual files in the directories containing the .CUD files or one file containing all results.
 
  


Reply

Tags
bash, script



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
[SOLVED] Search for a character in specific word in file and replace it in the word RM2015 Linux - Newbie 9 06-02-2015 07:38 AM
Explain ark.intel.com CPU counting and linux counting? postcd Linux - Hardware 9 06-27-2014 01:24 PM
find specific named directory while excluding specific named directory sharky Linux - Newbie 6 01-17-2014 11:29 AM
How to find a specific word between two lines having same another word.. say_hi_ravi Programming 4 04-18-2013 06:37 PM
How to convert specific word into specific colors in console shell? arfal Linux - Server 3 05-10-2012 12:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:28 PM.

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
Open Source Consulting | Domain Registration