4

I have a program that returns me a list of file names. I need to pass these file's contents to another program.

I know how to use cat to pass content:

cat file1 file2 file3 | some_program

what I want to do is something like:

list=`get_file_list`
cat ${list} | some_program

Though doing the above will simply pass the content of the list variable, rather than the files' content.

AriehGlazer
  • 2,220
  • 8
  • 26
  • 29
  • No, `cat ${list}` concatenates the contents of the files named in `$list`. If that's not what you want, I don't understand your question. – tripleee Jul 08 '12 at 07:16
  • `echo "$list" | some_program` will pass the contents of the variable to the standard input of the program. – Dennis Williamson Jul 08 '12 at 11:05

1 Answers1

12

To pass the output of,a program to another you can use xargs, for example

     find . -name "myfile*" -print | xargs grep "myword" $1

This one searches for files called myfile* and look for a key inside of them.

JayZee
  • 851
  • 1
  • 10
  • 17
  • 1
    If that's a correct answer then `some_program \`get_file_list\`` is a simpler way to accomplish that in this particular case. – tripleee Jul 08 '12 at 08:13
  • yeah! thx. Pls correct me if wrong; general format is something like: .... | xargs $1 command $1 ... – pedro May 23 '21 at 23:06