ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 14.10, Mint 17.1 Cinnamon and Mate
Posts: 101
Rep:
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
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
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.
Distribution: Ubuntu 14.10, Mint 17.1 Cinnamon and Mate
Posts: 101
Original Poster
Rep:
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!
^ = 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.
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 "^".
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.