LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-17-2003, 12:04 PM   #1
Fegero
LQ Newbie
 
Registered: Sep 2002
Posts: 8

Rep: Reputation: 0
Angry Counting matching file extentions variable


I'm learning to work with Sed and Grep and I'm having a small problem. I want to count how many files are in the current directory with a specific file EXT.

For example I may want to know how many .txt files are in the current directory. I then want to put that count number into a variable.

I thought I could use grep and do something like:

mycounter=`grep *.txt` but this does not work. I believe I'm missing more parameters, but I am unsure what to place in there.

So am I heading in the correct direction, or is there a way I could use ls ?

Thanks for your help.

Fegero
 
Old 11-17-2003, 12:34 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 7,514
Blog Entries: 1

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
grep is used to check a value that's inside file's.

grep root /etc/passwd for example wil list all lines (1 in this case) that have the word root in them.

ls will list files, if you add *txt it will list all files ending with txt

wc prints the number of bytes, words, and/or lines

ls *txt | wc -l

The above command will list all files ending with txt (ls *txt) and count the amount of hits (wc -l)

See manpages to find out what other options each command has (man ls, man wc and man grep).

Hope this gets you on th right track again.

Last edited by druuna; 11-17-2003 at 12:36 PM.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting occurances in file stefaandk Linux - General 1 08-13-2005 08:55 AM
frontpage 2003 file extentions bwarn Linux - Software 4 11-12-2003 08:00 AM
changing file extentions Seraph Linux - Newbie 3 09-17-2003 02:42 PM
picking off file extentions in php antken Linux - General 3 08-14-2002 03:49 PM
Couldn't find matching file system: LABEL=/user1 kausik Linux - General 4 05-20-2002 06:00 AM


All times are GMT -5. The time now is 08:47 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration