logo       

Re: can sed take take several line to produce multiple output: msg#00034

editors.sed.user

Subject: Re: can sed take take several line to produce multiple output

Hi,
your script is working but produce in 1 line...
the \n doesn't work!


--- Tim Chase <sed@xxxxxxxxxxxxx> wrote:

> > Can sed take the following input:
> >
> > header,login - telnet ssh, Thu Dec 08 11:08:55
> 2005,
> > subject,abc,def,123,456, abc.linux.com.my
> >
> >
> > and produce:
> >
> > Thu Dec 08 11:08:55 2005, Name=abd 2name=def
> phone=123
> > phone2=245
> >>From : abc.linux.com.my Access=telnet ssh
>
> If I understand correctly, the following sed script
> should do the
> trick:
>
> sed 'N;s/.*- \([^,]*\),
>
\(.*\)\n[^,]*,\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),
> \(.*\)/\2,
> Name=\3 2name=\4 phone=\5 phone2=\6\n>From : \7
> Access=\1/'
>
> to reformat the file.
>
> If you only want records for a given Name=, you can
> do
>
>
> sed 'N;s/.*- \([^,]*\),
>
\(.*\)\n[^,]*,\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),
> \(.*\)/\2,
> Name=\3 2name=\4 phone=\5 phone2=\6\n>From : \7
> Access=\1/;/Name=abc/!d'
>
> Those are both one-liners, in case either of our
> mailers bung it.
>
> It basically just joins the two adjacent lines into
> a single
> buffer for manipulation, picks out the fields of
> interest,
> reformats them in your desired format, and then, if
> they don't
> match the name you want to filter on. The second
> version then
> check to see if it contains "Name=abc"...if it
> doesn't, then it
> deletes the whole thing and moves on to the next
> 2-line pair.
>
> It's been a while since I've used more than about 4
> of those
> backreferences...seven was quite a hairball :)
>
> -tim
>
>
>
>
>
>
>


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


------------------------ Yahoo! Groups Sponsor --------------------~-->
AIDS in India: A "lurking bomb." Click and help stop AIDS now.
http://us.click.yahoo.com/9QUssC/lzNLAA/TtwFAA/dkFolB/TM
--------------------------------------------------------------------~->

--

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/

<*> To unsubscribe from this group, send an email to:
sed-users-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/






<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise