LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Editing Question... (https://www.linuxquestions.org/questions/linux-general-1/editing-question-14512/)

Trev 02-18-2002 10:38 AM

Editing Question...
 
Hi,

Firstly I see alot of LFS listed by people's distrobutions, is there a website were i can look for more info?

I would just like to know, i have a text files lets say it's the aliases file what i want to do is fix the layout up.

Instead of having:
user1: blah@blaho.com
user2: ____hello@hello.com
user4: ___test@test.com

I want to align the left and the right column
so all the text is under eachother for the right column
is there any command u can use in vi, sed to do this?;)

cat /etc/aliases | tr -s ' ' $'\t' <-- this only puts then in tabs doesn't aline them

dorward 02-18-2002 12:19 PM

Re: Editing Question...
 
Quote:

Originally posted by Trev
Hi,

Firstly I see alot of LFS listed by people's distrobutions, is there a website were i can look for more info?

http://www.linuxfromscratch.org.

Malicious 02-18-2002 01:38 PM

For the specific lines (assuming the _ are spaces):
user1: blah@blaho.com
user2: ____hello@hello.com
user4: ___test@test.com

A general regular expression search and replace:

s/\(user[0-9]:\) +/\1 /

In vi - :%s/\(user[0-9]:\) +/\1 /

Using sed:

cp /etc/aliases /etc/aliases.bak
sed 's/\(user[0-9]:\) +/\1 /' /etc/aliases.bak > /etc/aliases

Trev 02-18-2002 02:47 PM

Thanks for the reply, when i run :s/\(user[0-9]:\) +/\1 /
from vi, I get an error "substitution failed" any ideas?

Malicious 02-18-2002 05:05 PM

Did you miss the percent sign or is it a typo in your message?

Should be :%s... not :s...

Without the line range (% = all), s will only search the current line.

Trev 02-18-2002 05:21 PM

Sorry was a typo on my post, the command still does not work.

Malicious 02-18-2002 07:33 PM

My bad...

I missed an escape for the + character. Try:

s/\(user[0-9]:\) \+/\1 /
or
s/\(user[0-9]:\) */\1 /


All times are GMT -5. The time now is 07:52 AM.