LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   sed adding a space every time I run it (https://www.linuxquestions.org/questions/linux-software-2/sed-adding-a-space-every-time-i-run-it-4175593563/)

aristosv 11-15-2016 12:55 AM

sed adding a space every time I run it
 
I am using this to comment out lines that are not already commented out
Code:

sed -i '/^#/!s/\(.*\)/# \1/g' /var/rpi/scripts/display
and this to uncomment the line contaning the word omxplayer-youtube
Code:

sed -i '/omxplayer-youtube/s/^#//g' /var/rpi/scripts/display
The problem is that, every time I toggle this, a space is added to the begining of the line. I worked around this by running:
Code:

sed -i 's/^[ \t]*//' /var/rpi/scripts/display
But its not really a solution.
How can I stop the space from being added to the start of the line?
Thanks

syg00 11-15-2016 01:17 AM

You told it to add the blank character in your first sed.

Fix it.

astrogeek 11-15-2016 01:21 AM

The comment expression adds the space after the '#', the uncomment expression only removes the '#' leaving the added space.

Fix it by either not adding the space, or by removing the space.


All times are GMT -5. The time now is 10:43 AM.