I have some sample data below (call it test.txt). I would like to split this big document into 3 documents by searching the first two digits in the 4th column. I'm pretty new with Linux (Lubuntu 14.04) and have looked into 'csplit' and 'awk' but can't seem to get the syntax down for either. (I'm writing BASH scripts)
Before:
test.txt
12-1-2014 Allow 00:00:00 00:00:00
12-1-2014 Allow 00:00:00 00:00:00
12-2-2014 Allow 01:00:00 01:00:00
12-10-2014 Deny 01:00:00 01:00:00
12-10-2014 Deny 02:00:00 02:00:00
12-11-2014 Deny 02:00:00 02:00:00
After:
test1.txt
12-1-2014 Allow 00:00:00 00:00:00
12-1-2014 Allow 00:00:00 00:00:00
test2.txt
12-2-2014 Allow 01:00:00 01:00:00
12-10-2014 Deny 01:00:00 01:00:00
test3.txt
12-10-2014 Deny 02:00:00 02:00:00
12-11-2014 Deny 02:00:00 02:00:00
Something like that maybe :
Where :
is a loop that reads every line of FILE
means : if
<command>
outputs a non-zero lenght string, then...means : read "these are something", keep only the last column, and see if "thing" is in it.
means : I print "something" in FILE, without overwriting anything and by creating it if it doesn't exist yet.
With
awk
, you could just doIn pure
bash
I'm not sure the best way - although you could do something likeTry this script:
For each line in file, command
cut
splits line first forspace
, then for:
. The result is used as suffix for file.Output are:
that containing line for hour 00, 01 and so on.