Click here to Skip to main content
13,195,026 members (86,761 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I displayed all the files from a directory using the cmd,

ls /home/user1/. Now I need to display all content of particular files present in this directory

For ex.

ls /home/user1/tmp/ containt three files
sample1.txt sample2.txt sample3.txt sample5.js sample6.html

How to display only the content of .txt files present in these files

I have tired ls /home/user1/tmp/ | grep '.txt$' | cat /home/user1/tmp

But it is not working as I need.

Please help. Thanks in advancd
Posted 19-Nov-12 23:15pm
Updated 19-Nov-12 23:29pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just use a wildcard with cat:
cat /home/user1/tmp/*.txt
srmohanr 20-Nov-12 5:35am
Thanks for your great help.

Please tell me how to count the number of blank lines in those contents

I have tried cat /home/user1/tmp/*.txt | grep -n | wc -l
Graham Breach 20-Nov-12 5:42am
This works for me:
cat /home/user1/tmp/*.txt | egrep '^$' | wc -l
srmohanr 20-Nov-12 5:56am
Thanks for your great help
srmohanr 20-Nov-12 6:01am
what should do to execute commands under the presently working directory and without using './'.
For example:

I am under ~/sample, I have a command "mycmd" in this folder. How can I execute the it by using $mycmd
srmohanr 20-Nov-12 6:03am
'mycmd' already has an execute permission.
Graham Breach 20-Nov-12 6:06am
If you really want to do that, you will have to add "./" to your path. Exactly how you do that depends on which shell you are using.

Having to use "./" means that you do not accidentally run files in the current directory, which is a good thing.
srmohanr 20-Nov-12 6:10am
It have tried export PATH=~/sample:$PATH

It's working.

Thanks for your valuable information.
srmohanr 20-Nov-12 6:39am
I have a file contains group of words from a to z. Now I need to get all the words that have a,e,i,o,u in order

For example : abstancious.

I have tried cat /home/user1/tmp/file.txt | grep [aeiou]

But it showing all files that starts with those words.

Please help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171018.2 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100