Unix: how is a cat of two inputs?

in UNIX script programming, cat is a command that can combine two files:

cat file1 file2 > file3

this generates a third combination of the first two.

Also, a cat can be used with a pipe:

cat file1 | tail -4

this list will list the last 4 lines of file 1.

question: how could I combine the last 4 lines of file 1 and 2 to generate file 3?

I got a little lost here: how to give 2 input streams for cat?

+5
source share
4 answers

Bash has a process replacement :

  cat <(tail -4 file1) <(tail -4 file2)

I often use this function to change slightly modified versions of two files.

+5
source

You can do the following (in bash):

(tail -4 file1; tail -4 file2) > file3

cat , , .

+8

pee moreutils .

pee 'tail file1' 'tail file2' </dev/null > file3
+2
source

What happened with:

cat file1 | tail -4 > ./file3; cat file2 | tail -4 >> ./file3

?

+1
source

All Articles