473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Basic Unix Help

17
I am just beginning to learn how to use Unix and its commands. Assuming my home directory is named LearnCS, I want to write out the command to count how many files I have in my home directory that end with the extension *.txt with the resultant answer being a single number.

I believe I need to use grep and piping, but I'm not exactly sure...something like:

grep LearnCS *.txt | wc -l

Maybe? Any suggestions would be greatly appreciated!
Feb 3 '08 #1
2 1456
numberwhun
3,509 Expert Mod 2GB
I am just beginning to learn how to use Unix and its commands. Assuming my home directory is named LearnCS, I want to write out the command to count how many files I have in my home directory that end with the extension *.txt with the resultant answer being a single number.

I believe I need to use grep and piping, but I'm not exactly sure...something like:

grep LearnCS *.txt | wc -l

Maybe? Any suggestions would be greatly appreciated!
Actually, what you have their will look into each file that matches "*.txt" and search for "LearnCS".

Instead, what you want to do is take a listing, then pipe it through grep for your pattern, then pipe that through wc, like so:

Expand|Select|Wrap|Line Numbers
  1. ls /home/LearnCS | grep ".txt" | wc -l
  2.  
You don't need the * ".txt" because it isn't doing any type of globbing, instead, it is just a pattern to be looked for. I am only doing an "ls" and not an "ls -l" because I don't want the full listing, just the file names in the directory.

Just as a help to you, here are some links to some good sites for Unix commands and learning Unix. There are many, but these are some that I found:

Unix Command Reference Card
Intro to Unix Commands
Unix Tutorial For Beginners

Happy learning!

Regards,

Jeff
Feb 3 '08 #2
docdiesel
297 Expert 100+
Hi,

Expand|Select|Wrap|Line Numbers
  1. ls $HOME/*.txt | wc -l
should be enough. Except if you've got txt files in subdirectories (use ls -R with -R for recursive listing) and aren't sure if they end on .txt or .TXT (use grep -i with -i for case insensitivity):
Expand|Select|Wrap|Line Numbers
  1. ls -R $HOME | grep -i ".txt" | wc -l
Regards,

Bernd
Feb 3 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jm | last post by:
I manually put a datagrid in on a form. I then added this code to an event to populate it: OdbcConnection conn = new OdbcConnection("DSN=CardBase"); sqlCardHolders = "SELECT * FROM...
0
by: monkeycool | last post by:
This is for my intro to computer programming class. Please help me solve these 2 assignments: For the following items, you are to write the source code solution to each problem using the...
4
by: corky20 | last post by:
Can someone help...i've only started learning visual basic and i'm pretty new to programming(i know but everyones been there at one point) and need help with a question! A man is paid at the...
4
by: bilalbajwa2336 | last post by:
I want to make a program in visual basic. When i put my salary data in VB (like: Time In , Time Out, DAte, DAy) VB automatically (in the back ground) input this data in the Excel and Show out puts of...
3
by: walmsld | last post by:
Hi Everyone, This is a really basic query, so I really do hope that there is simple affirmative answer. I have a friend , honest-it wasn't me, who has locked themselves out of their computer...
2
by: traju | last post by:
Hi Friends, I am new user in unix o/s,i have a small ques what is the difference b/w unix shell scripts and korn shell scripts
3
by: bbatson | last post by:
New to visual basic; trying to teach myself. Here is very basic code I am using to try to fill a text box on my form after updating a box that selects an employee ID. Dim strsql As String strsql...
1
by: Eduard Allen | last post by:
I am a newbie to this site.. Would you help me to know on how to use the Data Report in Visual Basic 6.0 properly? I have my thesis, that's why I need to learn the process on how to use it.
0
by: gwmarin | last post by:
Hello, i am a complete beginner with visual basic so lets see if i can explain my problem. I've got microsoft excel 2003 which has got Visual Basic 6.5 and i need to create a macro which will click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.