Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-16-2012, 04:32 AM
|
#1
|
Member
Registered: Jun 2012
Location: ghaziabad , delhi , india
Posts: 105
Rep: 
|
Query !
what command i have to use for this query ?
List all the files which are starting from p character , and store all of these files in another dir using "pipeline" !
|
|
|
08-16-2012, 06:01 AM
|
#2
|
Member
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82
Rep: 
|
Hope this will help you
ls | grep ^p.* > /path/to/file
|
|
1 members found this post helpful.
|
08-16-2012, 06:18 AM
|
#3
|
Member
Registered: Jun 2012
Location: ghaziabad , delhi , india
Posts: 105
Original Poster
Rep: 
|
@ piyush sharma .
can you please tell me , that at the same time of sending that output to some file , can we display it in our screen !
|
|
|
08-16-2012, 06:29 AM
|
#4
|
Member
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82
Rep: 
|
I didn't get any other way, When redirection is used, all the text moves to that file.
you can try this :
ls | grep ^p.* > /path/to/file;cat /path/to/file
|
|
|
08-16-2012, 06:35 AM
|
#5
|
Member
Registered: Jun 2012
Location: ghaziabad , delhi , india
Posts: 105
Original Poster
Rep: 
|
I am asking this , because i find this query in "Sir yashwant kanitkar's" unix book , that in one line solve this query !
|
|
|
08-16-2012, 06:40 AM
|
#6
|
Member
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82
Rep: 
|
It does the same in "one line", What you say? problem is if we were to do it in "one command". because after semicolon, this (cat) is a new command.
|
|
1 members found this post helpful.
|
08-16-2012, 07:40 AM
|
#7
|
Member
Registered: Jul 2004
Distribution: slackware
Posts: 225
Rep:
|
isn't tee command meant for this multiple redirection (console and file)
|
|
1 members found this post helpful.
|
08-16-2012, 07:47 AM
|
#8
|
Member
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82
Rep: 
|
Quote:
Originally Posted by wigry
isn't tee command meant for this multiple redirection (console and file)
|
yes ! it works
ls | grep ^p.* |tee /path/to/file
|
|
|
08-16-2012, 07:55 AM
|
#9
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
The grep is unnecessary and can lead to false positives if there are files with a newline character in their name. Just do it this way:
Code:
ls p* | tee /path/to/file
|
|
|
08-16-2012, 08:08 AM
|
#10
|
Member
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82
Rep: 
|
Quote:
Originally Posted by TobiSGD
The grep is unnecessary and can lead to false positives if there are files with a newline character in their name. Just do it this way:
Code:
ls p* | tee /path/to/file
|
It is entering directory as well, if name starts from p, and listing all files of that directory. This may or may not be desired.
|
|
|
08-16-2012, 09:28 AM
|
#11
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
Quote:
Originally Posted by piyush.sharma
It is entering directory as well, if name starts from p, and listing all files of that directory. This may or may not be desired.
|
You are right. If that behavior is not desired just add the -d option to the ls command.
|
|
|
All times are GMT -5. The time now is 09:33 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|