That's a reasonably clever bit of code.
Sed, as you can learn in a good tutorial, works on addresses and commands. If the address is omitted the command runs on every line, such as the commonly seen
An address can be a line number, or a regex. Or it can be a comma-separated address range, which I won't describe further. (See tutorial linked above for details.)
A command can be a single command, or multiple commands contained in curly braces.
This sed command runs the
print command and then the
substitute command on line 1 of the input. The result is that after the first line of input will come a string of
***'s the same length.
You may notice that the
s command doesn't have any
print command after it, but at the end of each line whatever is held in the "pattern space" is implicitly printed, unless the
-n option was passed to sed in the first place. (Again, see the above-linked tutorial for more.)
Essentially, it's a quick way to make a pretty header for the table.
Edit to answer comment:
p command can be placed anywhere either at the start of the 1sed
or at the end? Also, the.` (period) means that the address is omitted?
No, not quite.
1 means, apply the following list of commands (enclosed within curly braces) only on the first line of input.
p means, print the current contents of the pattern space, followed by a newline. (The pattern space will at that time contain the first line of input, since that's how Sed works.)
s/./*/g means, for EVERY match (
globally) of the regex
. (which matches any character), substitute the character
*. This operates on the pattern space.
Then at the end of the commands (the close curly brace), since there are no more commands, the contents of the pattern space is implicitly printed. At this point it will just contain a bunch of asterisks (
Then the next line of input is read into the pattern space. Since the address
1 doesn't match, the curly brace block of commands is skipped. At the end of the curly brace block, since there are no more commands, the contents of the pattern space is implicitly printed. Repeat this paragraph as long as there is input. So the result is that the rest of the input after the first line is printed without change.
So the output will contain all the lines of the input, PLUS one line after the first line which will consist only of
* characters and which will be the same length as the first line.