LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-15-2016, 12:55 AM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 215

Rep: Reputation: 3
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
 
Old 11-15-2016, 01:17 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,769

Rep: Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571
You told it to add the blank character in your first sed.

Fix it.
 
Old 11-15-2016, 01:21 AM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,646
Blog Entries: 11

Rep: Reputation: 3674Reputation: 3674Reputation: 3674Reputation: 3674Reputation: 3674Reputation: 3674Reputation: 3674Reputation: 3674Reputation: 3674Reputation: 3674Reputation: 3674
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed help to run sed command against multiple different file names bkone Programming 2 04-16-2012 12:27 PM
How to measure kernel space time and user space time in linux bhas.bhaskar Linux - Newbie 1 11-28-2010 11:01 AM
user need to increase space to run a program its showing not enough space svani Red Hat 4 04-16-2010 04:04 AM
adding time zone files to the time GUI interface noir911 Red Hat 1 03-08-2010 08:18 AM
Adding programs to run during boot time JonnyW247 Linux - Software 1 02-05-2006 03:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration