0

I don't understand, while following cat command doesn't display contents of both file1.txt and file2.txt

cat file1.txt < file2.txt

It's displaying contents of file1.txt, but not the contents of file2.txt

while the following commands work as expected

cat file1.txt file2.txt
cat < file2.txt

Appreciate your help, in understanding the issue.

neon
  • 462
  • 6
  • 17

1 Answers1

3

You need to write it as follows

$ cat file1.txt - < file2.txt

if you want to mix file arguments with stdin.

Source man cat, Examples.

Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
  • thanks @ThorX89. I had gone through the man page, but it wasn't obvious to me. The only example in man page with stdin was "cat f - g". Any reason why cat need this special '-' for stdin redirection? – neon Dec 02 '13 at 02:27
  • I can only guess. If it didn't work like that and stdin were hardcoded to be the implicit first or the last file in the concatenation list, you'd still need an option to override the default if you wanted to place it somewhere else. Using a placeholder such as '-' solves the problem perfectly, and typing '-' is not really that much work as to warrant an implicit default. – Petr Skocik Dec 02 '13 at 02:41