So I have this file containing timestamps.
cat file
2022/01/27-00:47:05;2022/01/27-00:47:05;
2022/01/27-00:47:06;2022/01/27-00:47:06;
2022/01/27-00:48:59;2022/01/27-00:48:59;
2022/01/27-01:38:06;2022/01/27-01:38:06;
2022/01/27-01:45:17;2022/01/27-01:45:17;
2022/01/27-01:47:46;2022/01/27-01:47:47;
<bunch of lines>
2022/01/27-15:00:01;2022/01/27-15:00:01;
2022/01/27-15:00:05;2022/01/27-15:00:05;
2022/01/27-15:00:06;2022/01/27-15:00:06;
And I was trying to create a for loop to isolate all those lines whose first field is 2022/01/27-hour:.
So far, this is what I've come up with, but it's not working:
for var in {00..23}
do
awk -F ';' -v var="$var" '$1 ~2022/01/27-var"' file > $var.txt
done
I’m getting no output at all.
And what trying to accomplish is getting 24 files, whose content is hourly timestamps.
00.txt: all lines whose first field matches 2022-01-27-00
01.txt: all lines whose first field matches 2022-01-27-01
…/…
23.txt: all lines whose first field matches 2022-01-27-23
I'm clearly missing something, but I don't know what, because this other thing seems to work just fine.
for kk in {00..23}
do
echo | awk -v kk="$kk" '{print kk}'
done
00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
I must be passing the variable the wrong way.
Any help would be greatly appreciated.