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 ]