473,320 Members | 1,746 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,320 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 1454
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.