3

I am an absolute beginner at UNIX scripting (and have searched here for something explaining how to do this in a simple way to no avail). I am trying to pipe the contents of a claimName.txt file

find . -name 'claimName.txt' -exec cat {} \;

into a Node.js script that takes this value after a -c flag

npm run import -- -r ./ -c {claimName.txt contents go here}

What's the simplest way to pipe the claimName.txt contents to follow the -c flag?

1

You can use this without a pipe:

npm run import -- -r ./ -c "$(find . -name 'claimName.txt' -exec cat {} \; -quit)"
5
  • I know this wasn't in my original question, but is there a way to do this that strips out newlines? – fox Dec 7 '15 at 11:16
  • Try to replace the nmp..-c part with echo. On my host the content of any file is displayed without newlines. – Lambert Dec 7 '15 at 11:20
  • You force replacing newlines with spaces you can use $(find . -name 'claimName.txt' -exec cat {} \;|tr '\n' ' ') – Lambert Dec 7 '15 at 11:21
  • well, if you can do it without a pipe, you haven't demonstrated how here. and the dump of an entire text file (at least) into an unquoted substitution is straight-up crazy. – mikeserv Dec 7 '15 at 11:54
  • 2
    Fun fact: It's technically not a pipeless solution. Process substitution uses (system level) pipes internally. – PSkocik Dec 7 '15 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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