vi break apart multiple email addresses in one line.

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

a... [at] example.com; a... [at] example.net; a... [at] 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?
rhdyes [ Mi, 28 November 2007 00:10 ] [ ID #1880434 ]

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

rich wrote:
> I have a line in a file that reads like this:
>
> a... [at] example.com; a... [at] example.net; a... [at] 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
<Ctrl-V> and <Enter>. 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
Janis Papanagnou [ Mi, 28 November 2007 00:41 ] [ ID #1880435 ]

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

On Nov 27, 6:41 pm, Janis Papanagnou <Janis_Papanag... [at] hotmail.com>
wrote:
> rich wrote:
> > I have a line in a file that reads like this:
>
> > a... [at] example.com; a... [at] example.net; a... [at] 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
> <Ctrl-V> and <Enter>. 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.
rhdyes [ Mi, 28 November 2007 00:45 ] [ ID #1880436 ]

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

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

:g/. [at] ./s/;/\r/g

meaning:

"g/. [at] ./" foreach line in the file matching the pattern ". [at] ."
"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
Glenn Jackman [ Mi, 28 November 2007 00:46 ] [ ID #1880437 ]

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

On 11/27/2007 5:10 PM, rich wrote:
> I have a line in a file that reads like this:
>
> a... [at] example.com; a... [at] example.net; a... [at] 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.
Ed Morton [ Mi, 28 November 2007 00:51 ] [ ID #1880438 ]

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

On 28 Nov., 00:51, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 11/27/2007 5:10 PM, rich wrote:
>
> > I have a line in a file that reads like this:
>
> > a... [at] example.com; a... [at] example.net; a... [at] 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
Janis Papanagnou [ Mi, 28 November 2007 14:26 ] [ ID #1880449 ]

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

On Nov 27, 6:51 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 11/27/2007 5:10 PM, rich wrote:
>
> > I have a line in a file that reads like this:
>
> > a... [at] example.com; a... [at] example.net; a... [at] 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.
rhdyes [ Mi, 28 November 2007 19:22 ] [ ID #1880457 ]

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

On 11/28/2007 12:22 PM, rich wrote:
> On Nov 27, 6:51 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
>>On 11/27/2007 5:10 PM, rich wrote:
>>
>>
>>>I have a line in a file that reads like this:
>>
>>>a... [at] example.com; a... [at] example.net; a... [at] 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/. [at] ./s/;/\r/g

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

sed '/. [at] ./s/;/\r/g' file
awk '/. [at] ./{ 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.
Ed Morton [ Do, 29 November 2007 13:36 ] [ ID #1881338 ]

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

Janis Papanagnou wrote:

> Plain vi or vim? In vim you can do :%s/; /^M/g where ^M is typed as
> <Ctrl-V> and <Enter>. 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 <netnews [at] gclare.org.uk>
Geoff Clare [ Do, 29 November 2007 14:36 ] [ ID #1881341 ]

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

Post removed (X-No-Archive: yes)
Notifier Deamon [ So, 02 Dezember 2007 16:21 ] [ ID #1883852 ]

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

me at <my.address [at] is.invalid> 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/
markhobley [ So, 02 Dezember 2007 18:08 ] [ ID #1883853 ]
Linux » comp.unix.shell » vi break apart multiple email addresses in one line.

Vorheriges Thema: Top 10 posters comp.unix.shell
Nächstes Thema: If HISTTIMEFORMAT var is set, then 'history' command prints