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*

6
  • This solution currently prints timestamps of "commands" which are integer-comments, but doesn't print the comments themselves: printf "#1234512312\n#1231231233\n#1231231231\ncd\n#1237192388\nls\n#1231231231\ncd\n" | perl -ge ... produces #1234512312\n#1231231231\ncd\n#1237192388\nls\n (the "command" #1231231233 is omitted. As I noted in my solution, the specification from the question needs to be more clear in this case. Commented May 13, 2024 at 17:10
  • @Vilinkameni I know, it's written under "The big assumption being that that ^#[0-9]{10}\n will always positively identify the start of an entry in the file". The other way of tackling that would be to print all comments, but that would not discard empty commands. Handling both cases correctly is obviously impossible. Are you suggesting the second approach would be better? Commented May 13, 2024 at 17:18
  • As I said, the "correctness" of the approach depends on the specification, which currently doesn't cover this case. There is a comment by the OP in reply to @Ed Morton that the unix timestamp can be ignored and I just need to compare the command, in which case both this solution and my solution are correct, but it should be part of the question IMHO. Commented May 13, 2024 at 17:22
  • To be more precise, even that comment doesn't specify if "ignoring the timestamp" means leaving out the timestamps of empty commands (like in my solution), or having timestamps without the commands (like in this solution). Commented May 13, 2024 at 17:25
  • @Vilinkameni I loaded the page before you edited your comment, so I didn't see the last part of your first comment; I agree, it's unclear. Possibly your approach is more sensible. To be honest, I don't even know if empty entries could appear, while certainly a comment made of 10 digits could. Commented May 13, 2024 at 17:27