vi break apart multiple email addresses in one line.

vi break apart multiple email addresses in one line.

am 28.11.2007 00:10:13 von rhdyes

I have a line in a file that reads like this:

a...@example.com; a...@example.net; a...@example.com

I want to use vi to search for this pattern and put each address on a
new line in the file.

Any ideas?

Re: vi break apart multiple email addresses in one line.

am 28.11.2007 00:41:36 von Janis Papanagnou

rich wrote:
> I have a line in a file that reads like this:
>
> a...@example.com; a...@example.net; a...@example.com
>
> I want to use vi to search for this pattern and put each address on a
> new line in the file.
>
> Any ideas?

Plain vi or vim? In vim you can do :%s/; /^M/g where ^M is typed as
and . AFAIR, I couldn't do that in plain vi but I may
be mistaken und you may want to try it. (Ah, and if it's really just
one line than replace the % by a . (dot) while on that line.)

Janis

Re: vi break apart multiple email addresses in one line.

am 28.11.2007 00:45:12 von rhdyes

On Nov 27, 6:41 pm, Janis Papanagnou
wrote:
> rich wrote:
> > I have a line in a file that reads like this:
>
> > a...@example.com; a...@example.net; a...@example.com
>
> > I want to use vi to search for this pattern and put each address on a
> > new line in the file.
>
> > Any ideas?
>
> Plain vi or vim? In vim you can do :%s/; /^M/g where ^M is typed as
> and . AFAIR, I couldn't do that in plain vi but I may
> be mistaken und you may want to try it. (Ah, and if it's really just
> one line than replace the % by a . (dot) while on that line.)
>
> Janis

plain vi.

Re: vi break apart multiple email addresses in one line.

am 28.11.2007 00:46:21 von Glenn Jackman

At 2007-11-27 06:10PM, "rich" wrote:
> I have a line in a file that reads like this:
>
> a...@example.com; a...@example.net; a...@example.com
>
> I want to use vi to search for this pattern and put each address on a
> new line in the file.

:g/.@./s/;/\r/g

meaning:

"g/.@./" foreach line in the file matching the pattern ".@."
"s/;/\r/g" replace every ";" with a carriage return

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

Re: vi break apart multiple email addresses in one line.

am 28.11.2007 00:51:39 von Ed Morton

On 11/27/2007 5:10 PM, rich wrote:
> I have a line in a file that reads like this:
>
> a...@example.com; a...@example.net; a...@example.com
>
> I want to use vi to search for this pattern and put each address on a
> new line in the file.
>
> Any ideas?

We often see people asking to do text mainpulation jobs like this in vi and I've
often wondered "why vi?". It'd be easy in sed or awk or.... so I'm just really
curious about why so often the questions are about how to do it in vi - care to
elucidate?

Ed.

Re: vi break apart multiple email addresses in one line.

am 28.11.2007 14:26:39 von Janis Papanagnou

On 28 Nov., 00:51, Ed Morton wrote:
> On 11/27/2007 5:10 PM, rich wrote:
>
> > I have a line in a file that reads like this:
>
> > a...@example.com; a...@example.net; a...@example.com
>
> > I want to use vi to search for this pattern and put each address
> > on a new line in the file.
>
> > Any ideas?
>
> We often see people asking to do text mainpulation jobs like this in
> vi and I've often wondered "why vi?". It'd be easy in sed or awk
> or.... so I'm just really curious about why so often the questions
> are about how to do it in vi - care to elucidate?

I cannot speak for the OP; but I use vi in cases where the task can be
efficiently done with vi(m) and I have just a single file to process.
I experienced some types of replacements to be more bulky in sh/awk
than in vi, and the file handling overhead ("safe mv") is avoidable.
Also if you can't tell in advance where the range to consider for
processing is, or, in other words, if you have to determine the subset
of lines where to operate on by manual inspection anyway.

Janis

Re: vi break apart multiple email addresses in one line.

am 28.11.2007 19:22:22 von rhdyes

On Nov 27, 6:51 pm, Ed Morton wrote:
> On 11/27/2007 5:10 PM, rich wrote:
>
> > I have a line in a file that reads like this:
>
> > a...@example.com; a...@example.net; a...@example.com
>
> > I want to use vi to search for this pattern and put each address on a
> > new line in the file.
>
> > Any ideas?
>
> We often see people asking to do text mainpulation jobs like this in vi and I've
> often wondered "why vi?". It'd be easy in sed or awk or.... so I'm just really
> curious about why so often the questions are about how to do it in vi - care to
> elucidate?
>
> Ed.

For myself it was a project I started in vi and I am using it. I want
to know how to do this in vi. I have used sed before, but I am more
comfortable with vi than sed or awk.

Re: vi break apart multiple email addresses in one line.

am 29.11.2007 13:36:44 von Ed Morton

On 11/28/2007 12:22 PM, rich wrote:
> On Nov 27, 6:51 pm, Ed Morton wrote:
>
>>On 11/27/2007 5:10 PM, rich wrote:
>>
>>
>>>I have a line in a file that reads like this:
>>
>>>a...@example.com; a...@example.net; a...@example.com
>>
>>>I want to use vi to search for this pattern and put each address on a
>>>new line in the file.
>>
>>>Any ideas?
>>
>>We often see people asking to do text mainpulation jobs like this in vi and I've
>>often wondered "why vi?". It'd be easy in sed or awk or.... so I'm just really
>>curious about why so often the questions are about how to do it in vi - care to
>>elucidate?
>>
>> Ed.
>
>
> For myself it was a project I started in vi and I am using it. I want
> to know how to do this in vi. I have used sed before, but I am more
> comfortable with vi than sed or awk.

Thank you very much for responding. I understand where you're coming from - it
is hard to bite the bullet and learn a new tool, especially one that appears
complicated.

Having said that, what you're doing now is a little like if you were building a
house and now wanted to make a window so you were trying to figure out how to do
it using a hammer, since that's the tool you started your project with, rather
than learning how to use a circular saw. Yes, you can make a "window" using a
hammer, but you'll probably be much happier with the result if you learn to use
a circular saw.

To try to help you take a step in the right direction to the more appropriate
tools for general text manipulation, in this case, you got a "vi" (actually
"ed") solution that was:

:g/.@./s/;/\r/g

Assuming that works for you, the sed and awk equivalents would be:

sed '/.@./s/;/\r/g' file
awk '/.@./{ gsub(/;/,"\r"); print }' file

and if you want to have their output replace the contents of the original file,
it's just:

sed/awk '...' file > tmp && mv tmp file

Regards,

Ed.

Re: vi break apart multiple email addresses in one line.

am 29.11.2007 14:36:41 von Geoff Clare

Janis Papanagnou wrote:

> Plain vi or vim? In vim you can do :%s/; /^M/g where ^M is typed as
> and . AFAIR, I couldn't do that in plain vi but I may
> be mistaken und you may want to try it.

Yes, you can do that in plain vi. (The special treatment of ^M here is
specified by POSIX.)

--
Geoff Clare

Re: vi break apart multiple email addresses in one line.

am 02.12.2007 16:21:50 von unknown

Post removed (X-No-Archive: yes)

Re: vi break apart multiple email addresses in one line.

am 02.12.2007 18:08:02 von markhobley

me at wrote:

> sed -f $HOME/bin/email.sed email

or just use ed (That's sed without the s):

ed email

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/