Nadav
Nadav

Reputation: 13

Combine log files into 1 great report using a bash script/command

I've got 3 (or more) log files and I wish to create a combined log report when the output of each file is in a different column.

Example:

$ cat log1

test1
1
1
1

$ cat log2

test2
2
2
2

What I'm looking for is a way to create the below report into a new log file:

test1 test2
1     2
1     2
1     2

Upvotes: 1

Views: 247

Answers (2)

nu11p01n73R
nu11p01n73R

Reputation: 26667

You can try paste

$ paste log1 log2
test1   test2
1       2
1       2
1       2

From man page

   paste - merge lines of files

   Write  lines  consisting  of  the sequentially corresponding lines from each FILE, separated by TABs, to standard output.  With no FILE, or when
   FILE is -, read standard input.

EDIT

When there are more lines in file2

$ cat log1
test1
1
1
1

$ cat log2
test2
2
2
2
2
2
2

$ paste log1 log2
test1   test2
1       2
1       2
1       2
        2
        2
        2

Upvotes: 1

Gilles Quénot
Gilles Quénot

Reputation: 185106

Try doing this :

paste file1 file2

Upvotes: 0

Related Questions