简体   繁体   中英

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

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

尝试这样做:

paste file1 file2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM