Skip to main content
simplified tab insertion
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

You could use sed as follows I think:

  1. save the first line into the hold space
  2. prepend an extra tab (column) from line #2 onward (this preserves the original column alignment of the header)
  3. at a specified following line (I used line #4 in the example below), swap the hold back into pattern space, strip whitespace from it, and prepend it to the line
$ sed -e '1h' -e '2,$s/.*^/\t&\t/' -e '4{x;s/[[:space:]]//g;G;s/\n//}' file
                                CAT
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
    CAT         DOG     DOG     DOG     DOG     DOG     DOG     DOG
                DOG     DOG     DOG     DOG     DOG     DOG     DOG

You could use sed as follows I think:

  1. save the first line into the hold space
  2. prepend an extra tab (column) from line #2 onward (this preserves the original column alignment of the header)
  3. at a specified following line (I used line #4 in the example below), swap the hold back into pattern space, strip whitespace from it, and prepend it to the line
$ sed -e '1h' -e '2,$s/.*/\t&/' -e '4{x;s/[[:space:]]//g;G;s/\n//}' file
                                CAT
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
    CAT         DOG     DOG     DOG     DOG     DOG     DOG     DOG
                DOG     DOG     DOG     DOG     DOG     DOG     DOG

You could use sed as follows I think:

  1. save the first line into the hold space
  2. prepend an extra tab (column) from line #2 onward (this preserves the original column alignment of the header)
  3. at a specified following line (I used line #4 in the example below), swap the hold back into pattern space, strip whitespace from it, and prepend it to the line
$ sed -e '1h' -e '2,$s/^/\t/' -e '4{x;s/[[:space:]]//g;G;s/\n//}' file
                                CAT
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
    CAT         DOG     DOG     DOG     DOG     DOG     DOG     DOG
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

You could use sed as follows I think:

  1. save the first line into the hold space
  2. prepend an extra tab (column) from line #2 onward (this preserves the original column alignment of the header)
  3. at a specified following line (I used line #4 in the example below), swap the hold back into pattern space, strip whitespace from it, and prepend it to the line
$ sed -e '1h' -e '2,$s/.*/\t&/' -e '4{x;s/[[:space:]]//g;G;s/\n//}' file
                                CAT
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
                DOG     DOG     DOG     DOG     DOG     DOG     DOG
    CAT         DOG     DOG     DOG     DOG     DOG     DOG     DOG
                DOG     DOG     DOG     DOG     DOG     DOG     DOG