Adding a row to output of piped command

bash, ls, shell

Solution

If you want the headers to line up with the columns, you can use the aptly named `column` utility (a BSD extension, but it also comes with most Linux distros). To reformat existing text into aligned columns, use the `-t` option.

You can insert the column headers using a compound statement:

command1 | command2 | { echo Header1 Header2 Header3; command3 } | column -t

or:

{ echo Header1 Header2 Header3; command1 | command2 | command3 } | column -t

(whichever you find more readable.)

Note that the headers may not have spaces in them, and nor may the data-elements. If your data is not white-space separated, you can specify a different delimiter with the `-s` option; remember to use the same delimiter for your headers.

`column` left-justifies all columns, so numeric columns don't look as nice as you might want them to.

Problem

I have a piped command say ``` command1 | command2 | command3 ``` or lets say something like ``` ps | grep "something" ``` Now to the output of the command I would like to add to each coloumn some label or data to the top using shell script. EDIT In short this is what i want ``` InsertedLabel1 Inslabel2 Inslabel3 Data1frompipe Data1frompipe Data1frompipe Data2frompipe Data2frompipe Data2frompipe ``` What is an easy way to acheive this?

Original source