Sunday, January 24, 2010

[LINUX_Newbies] Re: hosts file duplicate entries

 

On 23Jan2010 22:43, Emil Payne <ehspayne@angelwoodpines.org> wrote:
| > I'd try this (untested):
| >
| > sed 's/ *#.*//; s/ */ /g; s/ $//' < /etc/hosts | sort -u >newhosts.txt
| >
| > Be careful with the cut/paste. The sed command has in the quotes, _two_
| > spaces
| > then one space then _three_ spaces then one then one. It:
| > strips comments
| > replaces all instances of two or more spaces with one space
| > strips any trailing spaces
| > and then pipes the tidies up data through sort.
[...]
| Ok, interesting results -
|
| 1. it got rid of all comments fine
|
| 2. it placed a space between EVERY character in the new file

Yeah, reread my paragraph; it looks above like the spaces have been
mangled. To repeat:

Be careful with the cut/paste. The sed command has in the quotes, _two_
spaces then one space then _three_ spaces then one then one.

You've got exactly one space each time. So:

s/ */ /g

will replace 0 or more spaces. I had

s/ */ /g

with _three_ spaces, meaning _2_ or more spaces get replaced.

| 3. I still have a bunch of duplicate lines right next to each other.

Can you post a few such dups?

Cheers,
--
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Politics - From the Greek Poly, meaning many, and the English Tics, meaning
little blood sucking insects.
- copyright 1991, Joshua J. Fielek, DoD#385, jjf@inri.com

__._,_.___
To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.
.

__,_._,___

No comments:

Post a Comment