-
Notifications
You must be signed in to change notification settings - Fork 0
/
split.sh
executable file
·31 lines (21 loc) · 912 Bytes
/
split.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
input="$1"
timestamp="$2"
# Separate a log file in two : every logged activity after $timestamp will now be in a separate file
# as if activity-logger had restarted
([ ! -f "$input" ] || [ -z $timestamp ]) && { echo "Usage : $0 input.wins timestamp"; exit; }
output="$(LC_ALL=en_US.utf8 date --date=@$timestamp +"%d-%m-%Y_%Hh%Mm%S").wins"
echo -en "Starting at $(LC_ALL=en_US.utf8 date --date=@$timestamp +"%a %b %d %T %Y")\n\n" > $output
# Print to new file
sed -n "/^\[$timestamp/,\$p" $input >> $output
# Delete from first file
sed -n "/^\[$timestamp/q;p" -i $input
t2=$(tail -n 1 $input | sed 's/\[\([0-9]*\)-.*/\1/')
touch -d@$t2 $input
echo "Old file : $input"
echo "New file : $output"
touch -d @$timestamp $output
stat $output
# If change 'change' time :
# NOW=$(date) && date -s "@$timestamp" && touch $filename && date -s "$NOW"
# Would be better with ntp ... but system-dependant