Timeline for sed: invalid usage of line address 0
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 3 at 11:59 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 |
That `$in` wasn't helping much wrt legibility.
|
Oct 3 at 11:46 | comment | added | choroba | @StéphaneChazelas: True. Fixed, thanks. | |
Oct 3 at 11:45 | history | edited | choroba | CC BY-SA 4.0 |
deleted 5 characters in body
|
Oct 3 at 8:51 | comment | added | Stéphane Chazelas |
That $in = 1 if $d + 30 * 24 * 60 * 60 > localtime doesn't set $in back to 0 when a timestamp is found for earlier dates. So you might as well skip the time parsing after the first timestamp from 30 days ago has been seen. Or use $in = $d + 30 * 24 * 60 * 60 > localtime
|
|
Sep 26 at 20:08 | comment | added | choroba |
@Raffa: Oh, you're right. When using something else, I'm getting sed: -e expression #1, char 3: unexpected `,'
|
|
Sep 26 at 18:27 | comment | added | Raffa |
Yep, that one is clear to me … However, without escaping the first tilde as in the OP, sed seems to have treated it like first~step … That error message wouldn't be the same with a different choice for a delimiter like | for example.
|
|
Sep 26 at 14:09 | comment | added | choroba |
@Raffa: No, they use ~ instead of / for an address, not the first~step form. That's why there's a comma after the zero.
|
|
Sep 26 at 12:59 | comment | added | Raffa |
... or bring the last command outside the quotes and shell escape the ! like sed "0,\~$date_pattern~"{//\!d} file ... OP seems to be using GNU sed which uses the tilde to set action for every N line starting from a certain line number like seq 6 | sed '0~3s/./x/' i.e. first~step so expecting 0~N and not 0,~ ... hence the error reported in the OP invalid usage of line address 0 ... // is the last match.
|
|
Sep 26 at 12:50 | history | edited | choroba | CC BY-SA 4.0 |
added 476 characters in body
|
Sep 26 at 12:42 | comment | added | choroba |
@Aleksey: sed "0,\~$date_pattern~{\~$date_pattern~p;d}" seems to work.
|
|
Sep 26 at 10:34 | comment | added | Aleksey |
It works, thank you. Is there a way to keep line contains $date_pattern ? Cause it removes 01/Jan/2025:00:00 and keep values. I want to keep this date too
|
|
Sep 26 at 8:27 | history | answered | choroba | CC BY-SA 4.0 |