LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Query ! (https://www.linuxquestions.org/questions/linux-newbie-8/query-4175422370/)

tushar_pandey 08-16-2012 04:32 AM

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" !

piyush.sharma 08-16-2012 06:01 AM

Hope this will help you
ls | grep ^p.* > /path/to/file

tushar_pandey 08-16-2012 06:18 AM

@ 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 !

piyush.sharma 08-16-2012 06:29 AM

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

tushar_pandey 08-16-2012 06:35 AM

I am asking this , because i find this query in "Sir yashwant kanitkar's" unix book , that in one line solve this query !

piyush.sharma 08-16-2012 06:40 AM

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.

wigry 08-16-2012 07:40 AM

isn't tee command meant for this multiple redirection (console and file)

piyush.sharma 08-16-2012 07:47 AM

Quote:

Originally Posted by wigry (Post 4755544)
isn't tee command meant for this multiple redirection (console and file)

yes ! it works
ls | grep ^p.* |tee /path/to/file

TobiSGD 08-16-2012 07:55 AM

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

piyush.sharma 08-16-2012 08:08 AM

Quote:

Originally Posted by TobiSGD (Post 4755555)
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.

TobiSGD 08-16-2012 09:28 AM

Quote:

Originally Posted by piyush.sharma (Post 4755566)
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 01:00 AM.