MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
June
Sun Mon Tue Wed Thu Fri Sat
     
10
   
2016
Months
Jun


Fri, Jun 10, 2016 10:51 pm

How to get cat to process a file name provided in the output of another command

I wanted to pipe the output of the find command through the tail command and then pipe its outout into the cat command. E.g., I used the find command to locate the manual page for the curl command on a MacBook Pro running OS X as shown below:
$ find /usr/share/man -name curl\*
/usr/share/man/man1/curl-config.1
/usr/share/man/man1/curl.1
$

There were two man pages with "curl" as part of the file name, but I only wanted the second one, so I piped the output of find into tail, selecting the last line of output only with the -n 1 option.

$ find /usr/share/man -name curl\* | tail -n 1
/usr/share/man/man1/curl.1
$

I then wanted to have cat process that file name. I could have just typed the directory path and file name produced from the above sequence of commands or copied and pasted the result, of course, but I thought it would be useful to know a method to get cat to process the output from find for other situations. There is a simple method, using command substitution of getting cat to process a file name that find has located. One can simply use a command similar to cat `find [whatever]` as explained by Laurence Gonsalves in response to a Stack Overflow question How to pipe list of files returned by find command to cat to view all the files. The command subsitution takes the output of the command or commands between successive backtick characters and uses that as the argument for another command, in this case the cat command.

[ More Info ]

[/os/unix/commands] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo