How to use csplit command to split a log file by day?

1k Views Asked by At

I have a log file like bellow:

Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 01  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 02  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.
Jan 03  This the log of this day.

How could I split the file by day? I used command:

csplit log /*Jan 01*/ /*Jan 02*/ /*Jan 03*/

but there is error:

csplit: /*Jan: closing delimiter '/' missing

So anyone could please tell me how to fix this? Thanks in advance.

1

There are 1 best solutions below

0
On

The shell sees /*Jan as one argument, and 01*/ as another, and so on. You need to quote the arguments that have embedded spaces.

csplit log '/*Jan 01*/' '/*Jan 02*/' '/*Jan 03*/'