2

I would like to do something like

cat foo1 foo2 | How can I enter sometext from terminal | > foo3

where foo3 contains the contents of foo1 followed by sometext, followed by the contents of foo2.

My best try so far is

cat foo1 - foo2 > foo3

but I don't see the data of foo2 in foo3.

4
  • Please provide more information on this, also provide what you have tried and where are you stuck?
    – Chetna C
    Jun 25 '17 at 21:55
  • 1
    @Chetna C cat foo1 - foo2 > foo3
    – N.Ali
    Jun 25 '17 at 21:59
  • but I don't see the data of foo2 in foo3 Thanks
    – N.Ali
    Jun 25 '17 at 22:00
  • Your cat command in the comments (which, incidentally should be in your question) is a good one. What key did you use to end the input from the terminal and tell cat to continue with the next file (foo2)?
    – roaima
    Jun 25 '17 at 22:39
3

Your command is good:

cat foo1 - foo2 > foo3

But you shouldn't use Ctrl+C to terminate your input from the terminal. This interrupts the entire command. Use Ctrl+D.

1

You can achieve this using echo and cat. Following should work for you

echo 'Some text in between' | cat foo1 - foo2 > foo3
1
  • Thanks @Chetna for the help, but I needed to enter text from the terminal :)
    – N.Ali
    Jun 25 '17 at 22:12
0

@Chetna C probably has the answer you're looking for. But here's another that works in bash:

user@hostname ~/test
bash$ echo charlie > foo1

user@hostname ~/test
bash$ echo dennis > foo2

user@hostname ~/test
bash$ cat foo1 <(echo "mac") foo2 > foo3

user@hostname ~/test
bash$ cat foo3
charlie
mac
dennis

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.