Click here to Skip to main content
11,802,636 members (69,688 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Linux

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
Edited 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 at 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 at 20-Nov-12 5:42am
This works for me:
cat /home/user1/tmp/*.txt | egrep '^$' | wc -l
srmohanr at 20-Nov-12 5:56am
Thanks for your great help
srmohanr at 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 at 20-Nov-12 6:03am
'mycmd' already has an execute permission.
Graham Breach at 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 at 20-Nov-12 6:10am
It have tried export PATH=~/sample:$PATH

It's working.

Thanks for your valuable information.
srmohanr at 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
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CPallini 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,695
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2015
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