Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add spaces to first line and another amount of spaces to all other lines

I have a file where i need to put 7 spaces for the first line and 3 spaces for all the other lines.

So i did this (i put 1d to ignore the first line) :

sed -i '1 s/^/       /' $f
sed -i '1d s/^/   /' $f

It works for the first line spaces but the other one gives me this error :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sed: -e expression #1, char 4: extra characters after command

>Solution :

sed '
  # more spaces for the first line
  1s/^/              /
  # less spaces for all the other lines.
  1!s/^/   /
'

You can learn sed at https://www.grymoire.com/Unix/Sed.html#uh-25 https://www.gnu.org/software/sed/manual/sed.html .

You could also do like subtraction, add 4 spaces on first line and then 3 spaces everywhere. 1s/^/ /;s/^/ /

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading