Quantcast
Channel: sed - Confused what each field does - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by cas for sed - Confused what each field does

$
0
0

The sed script prints the first line of input and then prints a line of * characters of exactly the same width as the first line.

1{p;s/./*/g}
  • 1 is an address matching the first line of input only. i.e. the sed commands in the {} block apply only to the first line.
  • p - print the input without change
  • ; is a command separator, in this case separating the p command and the s/./*/g command.
  • s/./*/g - change every character to a *, and print the result.

Any remaining input (lines 2+) are printed unmodified if they exist as per sed's default behaviour (if used without the -n option)

The whole command:

column -t -s : <(echo Name:Age:Gender:Height:Weight) test.txt | sed "1{p;s/./*/g}"

uses column -t -s : to tabulate input consisting of the echoed string "Name:Age:Gender:Height:Weight" and the contents of file.txt. column's output is piped to sed to produce the line of ******s separating the header from the rest of the output.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>