LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 08-16-2012, 04:32 AM   #1
tushar_pandey
Member
 
Registered: Jun 2012
Location: ghaziabad , delhi , india
Posts: 105

Rep: Reputation: Disabled
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" !
 
Old 08-16-2012, 06:01 AM   #2
piyush.sharma
Member
 
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82

Rep: Reputation: Disabled
Hope this will help you
ls | grep ^p.* > /path/to/file
 
1 members found this post helpful.
Old 08-16-2012, 06:18 AM   #3
tushar_pandey
Member
 
Registered: Jun 2012
Location: ghaziabad , delhi , india
Posts: 105

Original Poster
Rep: Reputation: Disabled
@ 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 !
 
Old 08-16-2012, 06:29 AM   #4
piyush.sharma
Member
 
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82

Rep: Reputation: Disabled
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
 
Old 08-16-2012, 06:35 AM   #5
tushar_pandey
Member
 
Registered: Jun 2012
Location: ghaziabad , delhi , india
Posts: 105

Original Poster
Rep: Reputation: Disabled
I am asking this , because i find this query in "Sir yashwant kanitkar's" unix book , that in one line solve this query !
 
Old 08-16-2012, 06:40 AM   #6
piyush.sharma
Member
 
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82

Rep: Reputation: Disabled
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.
Old 08-16-2012, 07:40 AM   #7
wigry
Member
 
Registered: Jul 2004
Distribution: slackware
Posts: 225

Rep: Reputation: 53
isn't tee command meant for this multiple redirection (console and file)
 
1 members found this post helpful.
Old 08-16-2012, 07:47 AM   #8
piyush.sharma
Member
 
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82

Rep: Reputation: Disabled
Quote:
Originally Posted by wigry View Post
isn't tee command meant for this multiple redirection (console and file)
yes ! it works
ls | grep ^p.* |tee /path/to/file
 
Old 08-16-2012, 07:55 AM   #9
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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
 
Old 08-16-2012, 08:08 AM   #10
piyush.sharma
Member
 
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82

Rep: Reputation: Disabled
Quote:
Originally Posted by TobiSGD View Post
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.
 
Old 08-16-2012, 09:28 AM   #11
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by piyush.sharma View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Query (and maybe a dependent query) on alsamixer. ajaygarg Linux - Newbie 4 12-20-2011 12:31 AM
query rajatgoel Linux - Newbie 5 06-04-2009 08:40 AM
interesting MySQL query/view query :s mjh Programming 3 03-25-2008 07:30 AM
mysql use output of one query in another query secretlydead Programming 2 11-19-2007 01:25 AM
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 06:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration