LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2010, 06:20 PM   #1
WildDrake!
Member
 
Registered: Dec 2003
Location: Current Location: Colorado
Distribution: Ubuntu 14.10, Mint 17.1 Cinnamon and Mate
Posts: 101

Rep: Reputation: 15
Ubuntu -- A sed -e "script" question


I found the following sed command which is said to Enable Standard Ubuntu Repositories and I want to use it in a simple script I am working on writing, but I would like to understand what the -e "script" part is doing as I don't recognize the language it is written in or understand its meaning and do not wish to use it blindly.

I have been examining the file it is going to operate on hoping to gain some patten clues maybe, but no luck. Would someone mind explaining to me what the individual notations mean in the "script" portion of the command (and also direct me to a beginner's tutor on the subject?

echo "Enabling Standard Ubuntu Repositories"
sudo sed -i -e "s/# deb/deb/g" /etc/apt/sources.list

Thanks!
 
Old 05-13-2010, 06:27 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
It uncomments a line that starts with deb.
 
Old 05-13-2010, 06:32 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
To be more precise, it changes ALL instances of "# deb" to "deb", regardless of whether they are at the beginning of the line. To restrict it to the beginning of the line, it would have to be written like this:
sudo sed -i -e "s/^# deb/deb/g" /etc/apt/sources.list

Note also that the "-e" part is not required.

Excellent SED tutorial here: http://www.grymoire.com/Unix/
 
1 members found this post helpful.
Old 05-13-2010, 06:33 PM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Just to add to what smeezekitty said:
In scripts the hush sign (#)at the beginning of a line (with some exceptions) means a comment so a shell/program doesn't try to execute/interpret anything after #.
By removing # from line(s) starting with '# deb', you'll pass it to apt-get.
 
Old 05-13-2010, 06:45 PM   #5
WildDrake!
Member
 
Registered: Dec 2003
Location: Current Location: Colorado
Distribution: Ubuntu 14.10, Mint 17.1 Cinnamon and Mate
Posts: 101

Original Poster
Rep: Reputation: 15
Thanks everybody! That really helps a lot. It looks like there was indeed a tiny flaw in the original line. I will use the correction. The man page was really confusing me. I am looking forward to the tutor recommended! I kept looking at the "deb/deb/g" thing, thinking there are no lines with "deb deb" in them not realizing the / between the two debs was a swap of what was between the first two // of the statement! That is kind of cool!

Thanks again!
 
Old 05-13-2010, 06:57 PM   #6
Fabio Paolini
Member
 
Registered: Dec 2008
Location: Brazil
Distribution: Slackware 12 Debian 5
Posts: 52

Rep: Reputation: 17
Nothing to say

Last edited by Fabio Paolini; 05-13-2010 at 07:01 PM. Reason: The answer was already given.
 
Old 05-13-2010, 07:00 PM   #7
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
At last, the caret ^ says that the pattern must begin with the character that follows, in the case above "#".
Shouldn't it say the LINE must begin with the character that follows?
 
Old 05-13-2010, 07:11 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please mark as SOLVED once you have an answer
 
Old 05-13-2010, 10:40 PM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
The definition that I learned:

^ = the empty character at the beginning of the line

$ = the empty character at the end of the line

computer scientists invent new language in their attempts to make things clear--my favorite is "disambiguate".
 
Old 05-14-2010, 03:35 AM   #10
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
Originally Posted by pixellany View Post
The definition that I learned:

^ = the empty character at the beginning of the line

$ = the empty character at the end of the line

computer scientists invent new language in their attempts to make things clear--my favorite is "disambiguate".
I never thought about ^/$ this way. I guess the definition you learned is technically the correct one.
But then again, is there any difference in
sed 's/^deb/eb/' file.txt

between saying:
a) match lines starting with the string 'deb' and.....
b) match lines with the empty character at the beginning of the line followed by the string 'deb' and...

Well, although the underlying assumptions are quite different, they are both CLEAR in conveying the same meaning (match).

But I get your point about the benefits of precision and lack of ambiguity in scientific languages.
 
Old 05-14-2010, 09:17 AM   #11
Fabio Paolini
Member
 
Registered: Dec 2008
Location: Brazil
Distribution: Slackware 12 Debian 5
Posts: 52

Rep: Reputation: 17
I have removed my post above, because just after I have posted that I saw that the question was already well answered, sorry. But as sycamorex corrected me, then I decided to post once again.


Quote:
Quote:
At last, the caret ^ says that the pattern must begin with the character that follows, in the case above "#".
Shouldn't it say the LINE must begin with the character that follows?
Yes, I agree, it is better to say that the pattern matches lines that begin with the character that follows "^".
 
Old 05-14-2010, 02:00 PM   #12
WildDrake!
Member
 
Registered: Dec 2003
Location: Current Location: Colorado
Distribution: Ubuntu 14.10, Mint 17.1 Cinnamon and Mate
Posts: 101

Original Poster
Rep: Reputation: 15
In case someone interested is following this discussion....Here is my final version of this portion of my script:

First, I make a backup (just in case) of my source.list file -

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

Then comes the command to enable all repositories but skipping cdrom and all source code ( deb-src ) providing repositories -

sudo sed -i -e 's/^# deb http/deb http/g' /etc/apt/sources.list

This sweeps the entire file. I guess if I wanted to pick and choose among these to be more specific yet which repositories were enabled, I'd probably have to pretty much use the whole line from the source.list to make the pattern recognition individually, one at a time in my script....or maybe I haven't read far enough in the tutor yet!

Thanks for all your help and the following discussion which was very interesting to me.
 
Old 05-14-2010, 03:40 PM   #13
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by pixellany View Post
The definition that I learned:

^ = the empty character at the beginning of the line

$ = the empty character at the end of the line

computer scientists invent new language in their attempts to make things clear--my favorite is "disambiguate".
I thought they mean beginning/end of string, which just happens to be the beginning and end of a line for SED.

Maybe I'm wrong.
 
  


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
BASH script with sed file "inside"? SilversleevesX Linux - Newbie 6 02-25-2010 10:31 PM
sed - use sed to replace multiple instances from "x" to "y" in a line mrodmac Linux - General 4 02-02-2010 11:37 AM
bash question about sed '"$i"!d' listofusers haliban Programming 6 09-25-2008 06:42 PM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:10 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