-1

How can I node -pe "require('./package.json').version" with prefix HELLO into file?

node -pe "require('./package.json').version" | "HELLO" + $res > file.txt is not working.

I want to use single line command (not full multiline bash script)

Simple demo

echo "world" | "HELLO" + $res > file.txt

The expected output in file - HELLO world

neviyazive
  • 23
  • 3
  • 1
    Please add output of `node -pe "require('./package.json').version"` and your desired output for that sample input to your question. – Cyrus Jun 23 '19 at 06:56
  • 2
    See: [Add a prefix string to beginning of each line](https://stackoverflow.com/q/2099471/3776858) – Cyrus Jun 23 '19 at 07:00

1 Answers1

0
  • Your $res variable doesn't get set
  • Pipe is for redirecting the output of a program/script to the input of another program; this second program is missing in your line

The solution could be something like this (not tested):

echo "HELLO" + $(node -pe "require('./package.json').version") > file.txt

$(command substitution) captures the output of a command.

vintnes
  • 2,014
  • 7
  • 16
Enno Gröper
  • 4,391
  • 1
  • 27
  • 33