Really simple question, how do I combine echo and cat in the shell, I'm trying to write the contents of a file into another file with a prepended string?
If /tmp/file looks like this:
this is a test
I want to run this:
echo "PREPENDED STRING" cat /tmp/file | sed 's/test/test2/g' > /tmp/result
so that /tmp/result looks like this:
PREPENDED STRINGthis is a test2
Thanks.
echo $? returns the return value (exit status) of the last executed command (0 is usually success ).
You can also use echo to to redirect the standard output of the command on the left and append it to the end of the file on the right. The output will be added to the file hello. txt. Whereas the command cat displays the contents of one or more files to the terminal.
Echo is a Unix/Linux command tool used for displaying lines of text or string which are passed as arguments on the command line. This is one of the basic command in linux and most commonly used in shell scripts. In this tutorial, we will look at the different options of echo command.
This should work:
echo "PREPENDED STRING" | cat - /tmp/file | sed 's/test/test2/g' > /tmp/result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With