How to add literal text to the "cat" Unix command

I am trying to cat some files together while adding text between files. I am new to Unix and I have no syntax.

Here is my unsuccessful attempt:

cat echo "# Final version (reflecting my edits)\n\n" final.md echo "\n\n# The changes I made\n\n" edit.md echo "\n\n#Your original version\n\n" original.md > combined.md 

How to fix it? Should I use pipes or something else?

+6
source share
3 answers

If I understand you, it should be something like:

 echo "# Final version (reflecting my edits)\n\n" >> combined.md cat final.md >> combined.md echo "\n\n# The changes I made\n\n" >> combined.md cat edit.md >> combined.md 

Etc.

+5
source

Use a group of commands to combine output into a single stream:

 { echo -e "# Final version (reflecting my edits)\n\n" cat final.md echo -e "\n\n# The changes I made\n\n" cat edit.md echo -e "\n\n#Your original version\n\n" cat original.md } > combined.md 

There are tricks that you can play with substitution substitution and command substitution (see Lev Levitsky's answer) to do it all with one command (instead of the separate cat processes used here), but it should be quite efficient with so many files.

+6
source

The process override seems to work:

 $ cat <(echo 'FOO') foo.txt <(echo 'BAR') bar.txt FOO foo BAR bar 

You can also use command substitution inside this document.

 $ cat <<EOF FOO $(< foo.txt) BAR $(< bar.txt) EOF 
+4
source

All Articles