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*

2
  • You probably want to look into awk which is probably best suited for these tabular information operations. sed and cut are more useful for isolated incidents where you have a single delimited line and want to extract fields from it. Anytime you get more elaborate with it, you should switch over to awk Commented Jul 13, 2016 at 2:38
  • FYI This whole thing could be done in one 'real' SQL statement after one or maybe a few setup depending on your DBMS, and if the volume of data is large it would likely perform much better because DBMSs have sophisticated optimizers to deal with just this kind of data operation whereas shell does exactly and only what you tell it. But you don't want that so I won't suggest it. Commented Jul 14, 2016 at 6:53