[LINUX] Merge Apache access logs

Merge multiple log files into one

Sort and merge log files by date when date is the 4th element

$ sort -nmbsk4 log1.log log2.log > marge.log

Details of each option are as follows.

|option|Description| |------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | -n |Evaluate in numerical order. The character string at the beginning of the line(White space may be prefixed)As a numeric string. Numeric character string is at the beginning-Code(You don't have to), 0 or more digits, and decimal point and 0 or more digits(You don't have to)Consists of.| | -m |Sort and merge the given files together. Each input file must be sorted in advance. It is also possible to perform a sort operation in multiple files instead of a merge operation. The merge operation is provided(If this is fine)This is because it is faster.| | -b |Ignore whitespace at the beginning of each line when comparing.| | -s |Disable last resort comparison and leave the order of the rows where all fields had the same comparison result as the input order.| | -k | -K POS1[,POS2]POSIX format with sort field specification. This is recommended in the future. Specifies the fields from POS1 to POS2 on the row. Includes POS2. Until the end of the line if POS2 is omitted. Fields and character positions each start counting from 0.| Quoted from https://linuxjm.osdn.jp/html/gnumaniak/man1/sort.1.html.

Recommended Posts

Merge Apache access logs
Analyze Apache access logs with Pandas and Matplotlib
Customize Flask access logs