You are not logged in.
Wah! (= "hi!")
I'm trying to grep the last three days of a list - It's killing me:
| grep -e "\($(($(date +%d)-0))\|$(($(date +%d)-1))\|$(($(date +%d)-2))\) $(date +%b)"
echo grep[stufffromabove] says:
grep -e \(25\|24\|23\) Aug
... cat list.txt | grepstufffromabove shows no lines at all. Tried several variations of the line, started all over again a few times but I keep messing it up at some times... yes, and I must admit, I've been confusing myself using about 3 different "regex versions" today (uhm... sed, grep, perl, php?), so maybe I keep messing it up this way again....
Could someone tell me what I'm doing wrong?
Last edited by whoops (2009-08-25 19:08:08)
Offline
the following works for me:
#!/bin/bash
day_0=$(date +%d)
day_1=$((day_0-1))
day_2=$((day_0-2))
grep "$day_0\|$day_1\|$day_2" /var/log/everything.log
i guess `| grep -e \(one\|two\)` != `| grep "one\|two"`
EDIT: oh, now i see the issue. didn't notice that little month hangin on the end there...
try this version:
#!/bin/bash
month="$(date +%b)"
day_0=$(date +%d)
day_1=$((day_0-1))
day_2=$((day_0-2))
grep -E "[$day_0$day_1$day_2] $month" /var/log/everything.log
Last edited by brisbin33 (2009-08-25 18:20:55)
//github/
Offline
Thanks but...
I just sort of just figured out the obvious and noticed, that I'd even have a big problem if that regex of mine worked.... unluckily, there actually seem to be days with a number smaller than 3, but no negative days in the human calendar... so I'm going to rest first and think it over after that. Most likely I'm going to end up subtracting a day in unix-time and converting back, better ideas are not necessary but welcome .
(edit: oh, and thanks again - that might come handy when I ended up with the same $(\[chaos\]) trying the unix time version later)
Last edited by whoops (2009-08-25 18:29:30)
Offline
oh, haha hadn't notice that myself. good news is this might help you:
┌─[ 14:37 ][ blue:~ ]
└─> date +%d\ %b
25 Aug
┌─[ 14:37 ][ blue:~ ]
└─> date +%d\ %b -d "-1 days"
24 Aug
┌─[ 14:37 ][ blue:~ ]
└─> date +%d\ %b -d "-2 days"
23 Aug
//github/
Offline
date --date '-3 days'
Last edited by fogobogo (2009-08-25 18:39:15)
Offline
ooooh, ok, that made it easier than what I had in mind in the beginning, thanks. I guess I should just have read the whole date manpage.
| grep "$(date +'%d %b')\|$(date --date '-1 days' +'%d %b')\|$(date --date '-2 days' +'%d %b')" \
... does it.
Offline
not to mention a lot easier to read
coreutils ftw!
Offline
deleted, I misread the previous post
Last edited by Profjim (2009-08-25 20:47:29)
Offline