Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following bash command:

find repo -name '*.c'

What I want to do is use the files returned as arguments to my perl script, so that it's equivalent to running:

perl ./myscript file1.c file2.c file3.c ...

How can I do this?

share|improve this question
    
Hey, I think you had input confused with arguments (input is generally associated with a program's standard in stream, which is different from its arguments). I updated your question to reflect this based on the answer you selected and your comments on the answers. Feel free to revert the changes if they were incorrect. –  Darth Android Oct 17 '12 at 14:22
    
Thanks, your interpretation is correct. –  WonderCsabo Oct 17 '12 at 21:13

2 Answers 2

up vote 0 down vote accepted

Try

find repo -name '*.c' | xargs perl ./yourscript

This should be the same as

perl ./yourscript file1.c file2.c file3.c ...
share|improve this answer
1  
Thanks, it works. Another issue just came around: my dear users use spaces in file names. How can i wrap every file name with "" before replacing the \n-s to spaces? Sorry for being silly but i'm completely new to bash. EDIT: found answer stackoverflow.com/a/6041695/747412 –  WonderCsabo Oct 16 '12 at 17:44

You can try that :

find repository -name '*.c' -exec perl -pe 's:\n: :g' {} +

The delimiter in the substitution is : here, no need to use / both in Perl & sed.

If you prefer a real pipe :

find repository -name '*.c' | xargs cat | perl -pe 's:\n: :g'
share|improve this answer
    
Added pipe version –  sputnick Oct 16 '12 at 17:37
    
Okay, but i have a perl script, which i have to provide input like this: ./myscript.perl -args arg file1 file2 How can i pipe my file list to this script? Sorry if the OP was not clear. –  WonderCsabo Oct 16 '12 at 17:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.