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.

6
  • 1
    Your grep approach has no drawbacks. Just pipe it to paste 3 lines at a time and delimited by space and voila you get the desired output. Commented May 28, 2021 at 23:22
  • 1
    Infact it is theperl approach that is needlessly wieldy. You could just as well have written: perl -lne '$,=$"; print /(?=.*(?:^|\h)Inventory\h+for\h+(\S+)) (?=.*(?:^|\h)PID:\h+([^,]*),) (?=.*(?:^|\h)SN:\h+(\S{11})) /xg; ' file Commented May 28, 2021 at 23:24
  • @guest_7 your perl is great. I will be glad to you if you post it as an answers, with explanation comment Commented May 28, 2021 at 23:46
  • @guest_7 it has the one drawback that it requires GNU grep for -P and so, like the perl solution, won't be available on all Unix systems. Commented May 29, 2021 at 12:27
  • 2
    @YetAnotherUser that's absolutely fine, of course, I was just responding to guest_7 saying it has "no drawbacks" when in fact it has that one at least that perl isn't a mandatory POSIX tool, and the POSIX version of grep doesn't support -P and so those won't be available on all Unix boxes. Commented May 31, 2021 at 11:34