Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 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 Commented Sep 26 at 10:34
  • @Aleksey: sed "0,\~$date_pattern~{\~$date_pattern~p;d}" seems to work. Commented Sep 26 at 12:42
  • ... 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. Commented Sep 26 at 12:59
  • @Raffa: No, they use ~ instead of / for an address, not the first~step form. That's why there's a comma after the zero. Commented Sep 26 at 14:09
  • 1
    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 Commented Oct 3 at 8:51