Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.unix.shell > #1800
| From | "Ed Morton" <mortonspam@gmail.com> |
|---|---|
| Newsgroups | comp.unix.shell |
| Subject | Re: sed question |
| Message-ID | <201108231657242493@webuse.net> (permalink) |
| References | (4 earlier) <0.b01bcde01680c0daa6e8.20110821030744BST.87wre78qkv.fsf@bsb.me.uk> <j2pq8r$rs5$1@dont-email.me> <0.b732ebac660ce477a72b.20110821160537BST.87hb5a954u.fsf@bsb.me.uk> <j2r9uf$j4g$1@dont-email.me> <f6a2dc24-188b-4296-ac64-35ee504b965c@w22g2000prj.googlegroups.com> |
| Date | 2011-08-23 16:57 +0000 |
Rakesh Sharma <sharma__r@hotmail.com> wrote:
> On Aug 21, 8:58 pm, Ed Morton <mortons...@gmail.com> wrote:
> > On 8/21/2011 10:05 AM, Ben Bacarisse wrote:
> > > Ed Morton<mortons...@gmail.com> writes:
> >
> > >> On 8/20/2011 9:07 PM, Ben Bacarisse wrote:
> > >>> Ed Morton<mortons...@gmail.com> writes:
> >
> > >>>> On 8/20/2011 2:11 AM, hsteenk...@lycos.com wrote:
> > >>>>> On Aug 20, 3:32 pm, Seebs<usenet-nos...@seebs.net> wrote:
> > >>>>>> On 2011-08-20, hsteenk...@lycos.com<hsteenk...@lycos.com>
wrote:
> >
> > >>>>>>> Let say a file with a few lines of text. I need to write a
sed command
> > >>>>>>> that will duplicate each line in the output. This means each
line must
> > >>>>>>> be printed twice.
> >
> > >>>>>>> I can do the following:
> > >>>>>>> $ sed 'p' filename
> >
> > >>>>>>> How can I achieve the same with a sed substitute command?
> > >>> <snip>
> > >>>>> I am newbie and doing a sysadmin
> > >>>>> course. This is one of the questions that were asked in order
to get a
> > >>>>> better understanding of sed.
> >
> > >>>> Hopefully the intent of this question, then, is to teach you
what NOT
> > >>>> to do with sed.
> >
> > >>>> sed is an excellent tool for simple substitutions on a single line,
> > >>>> for anything else (like this!)
> >
> > >>> I'm not so sure this is one of those cases. Presumably
something like
> >
> > >>> sed -e 's/.*/[&]'
> >
> > >>> is a "simple substitutions on a single line" and I don't think
that's
> > >>> far from what the OP needs (being deliberately coy about a
solution).
> >
> > >> The only solution I've seen so far was from Janis in which went
something
like this:
> >
> > >>>>>> On my system the following does what you want...
> >
> > >>>>>> sed 's/.*/&\
> > >>>>>> &/'
> >
> > >>>>> Thx Janis. This works great on my system but each line is
appended ....
> > >>>>> and not displayed twice.
> >
> > >>>> This is why I said "on my system". Please make sure there's no
blank
> > >>>> character behind the \ , then try the same on your system
without the
> > >>>> final \ on the first line
> >
> > >>>> sed 's/.*/&
> > >>>> &/'
> >
> > >>>> Variants that may work on your system could also be one of
> >
> > >>>> sed "s/.*/&$'\n'&/"
> > >>>> sed 's/.*/&\n&/'
> >
<snip>
> One way to accomplish what the OP wants (i.e., use the s/// command)
> is:
>
> sed -e 'G;s/\(.*\)./&\1/' yourfile
>
> or,
>
> sed -e 'G;s/.*/&&/;s/.$//' yourfile
>
Rakesh - those solutions look a bit more complicated than the ones already
posted above. Would a solution like you posted be preferable to the
others that
were already posted above and if so why? Just curious...
Ed.
Posted using www.webuse.net
Back to comp.unix.shell | Previous | Next — Previous in thread | Next in thread | Find similar
sed question hsteenkamp@lycos.com - 2011-08-19 23:16 -0700
Re: sed question Seebs <usenet-nospam@seebs.net> - 2011-08-20 06:32 +0000
Re: sed question hsteenkamp@lycos.com - 2011-08-20 00:11 -0700
Re: sed question Michael Vilain <vilain@NOspamcop.net> - 2011-08-20 00:19 -0700
Re: sed question Seebs <usenet-nospam@seebs.net> - 2011-08-20 07:23 +0000
Re: sed question hsteenkamp@lycos.com - 2011-08-20 02:06 -0700
Re: sed question Seebs <usenet-nospam@seebs.net> - 2011-08-20 10:03 +0000
Re: sed question hsteenkamp@lycos.com - 2011-08-20 04:51 -0700
Re: sed question Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-08-20 14:59 +0300
Re: sed question hsteenkamp@lycos.com - 2011-08-20 05:16 -0700
Re: sed question Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-08-20 15:47 +0300
Re: sed question hsteenkamp@lycos.com - 2011-08-20 06:35 -0700
Re: sed question Ed Morton <mortonspam@gmail.com> - 2011-08-20 07:36 -0500
Re: sed question Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-08-20 13:28 +0000
Re: sed question Jens Schweikhardt <usenet@schweikhardt.net> - 2011-08-20 16:24 +0000
Re: sed question Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-08-20 18:03 +0000
Re: sed question pk <pk@pk.invalid> - 2011-08-20 23:06 +0200
Re: sed question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-21 03:07 +0100
Re: sed question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-21 03:09 +0100
Re: sed question Ed Morton <mortonspam@gmail.com> - 2011-08-20 21:24 -0500
Re: sed question Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-08-21 06:07 +0300
Re: sed question Ed Morton <mortonspam@gmail.com> - 2011-08-20 23:08 -0500
Re: sed question Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-08-21 15:21 +0300
Re: sed question Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-08-21 13:40 +0000
Re: sed question Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-08-22 22:25 +0300
Re: sed question Aragorn <stryder@telenet.be.invalid> - 2011-08-22 22:03 +0200
Re: sed question Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-08-22 23:33 +0300
Re: sed question Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-08-22 21:28 +0000
Re: sed question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-21 16:05 +0100
Re: sed question pk <pk@pk.invalid> - 2011-08-21 17:09 +0200
Re: sed question Ed Morton <mortonspam@gmail.com> - 2011-08-21 10:58 -0500
Re: sed question Rakesh Sharma <sharma__r@hotmail.com> - 2011-08-22 15:11 -0700
Re: sed question Ed Morton <mortonspam@gmail.com> - 2011-08-22 19:17 -0500
Re: sed question "Ed Morton" <mortonspam@gmail.com> - 2011-08-23 16:57 +0000
Re: sed question Rakesh Sharma <sharma__r@hotmail.com> - 2011-09-04 06:17 -0700
Re: sed question Marc Girod <marc.girod@gmail.com> - 2011-08-21 06:30 -0700
Re: sed question merlyn@stonehenge.com (Randal L. Schwartz) - 2011-08-21 08:10 -0700
Re: sed question "Chris F.A. Johnson" <cfajohnson@gmail.com> - 2011-08-20 18:50 -0400
Re: sed question Stephane CHAZELAS <stephane_chazelas@yahoo.fr> - 2011-08-22 17:46 +0000
csiph-web