From: Ben Bacarisse on 26 Sep 2009 08:50 sharma__r(a)hotmail.com writes: > sed -e ' > /^([^)]*)/{ > h; # remember the (qqq) part > d > } > > / [1-9][0-9]*$/{ > G; # strap the (qqq) part to the list > s/\n/ / > } > ' yourfile > > For other shells you could put the sed commands into a file & then > invoke sed with the -f option. Rats! I tried something along those lines and gave up. I think I must have had a typo in what in was trying, which was, in essence, this: sed -n '/(.*)/{h;d};{G;s/\n/ /p}' (not sure why I was using -n and not simply dropping the 'p' but that's the nature of "fiddling" I suppose). Anyway, thanks. It was irritating me... -- Ben.
From: vjp2.at on 26 Sep 2009 21:01 Thanks so much. SED is not an absolute requirement. But so far the rest of the project is in SED. I do want to learn PERL. I've fiffled a bit. *+-sed -e ' *+- /^([^)]*)/{ *+- h; # remember the (qqq) part *+- d *+- } *+- / [1-9][0-9]*$/{ *+- G; # strap the (qqq) part to the list *+- s/\n/ / *+- } *+-' yourfile - = - Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist http://www.panix.com/~vjp2/vasos.htm http://www.facebook.com/vasjpan2 ---{Nothing herein constitutes advice. Everything fully disclaimed.}--- [Homeland Security means private firearms not lazy obstructive guards] [Urb sprawl confounds terror] [Phooey on GUI: Windows for subprime Bimbos]
From: Chris F.A. Johnson on 27 Sep 2009 16:48 On 2009-09-27, Igor Pozgaj wrote: > On Fri, 25 Sep 2009 13:31:56 -0700, Ed Morton wrote: > >> sed is a great tool for simple substitutions on a single line, for >> anything else use awk, perl, etc. >> >> awk '/^\(/{ h=$0;next } { print $0,h }' file > > FUD > > sed '/(/{h;d};G;s/\n/ /' input.txt I think you just demonstrated Ed's point. (And that's not standard sed syntax; it will not work with many versions of sed.) -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence
From: Kaz Kylheku on 28 Sep 2009 05:01 On 2009-09-25, Sidney Lambe <sidneylambe(a)nospam.invalid> wrote: > Ed Morton <mortonspam(a)gmail.com> wrote: >> sed is a great tool for simple substitutions on a single line, for >> anything else use awk, perl, etc. > > Most experts in this area would disagree with that statement, Note that anything sed can do can also be done by a machine consisting of a read/write head, a tape of symbols, and a few rules. Nobody who confuses computability with expressivity can be regarded as a bona fide expert in computing.
From: Michael Paoli on 28 Sep 2009 07:02 On Sep 25, 10:59 am, vjp2.at(a)at.BioStrategist.dot.dot.com wrote: > I have a file that has a series of lists > > (qqq) > aaa 111 > bbb 222 > > and I want to make it look like > > aaa 111 (qqq) > bbb 222 (qqq) > > where some lists have only aaa > and some have both or more but all end in a number > > the list should be considered ended if another (qqq) shows up Well, ... I find the "specification" to be rather ambiguous, but within the realm of reasonable interpretations of specified behavior ... /^(qqq)$/h;/[0-9]$/{;G;s/\n/ /;p;} e.g.: $ echo '(qqq) > aaa 111 > bbb 222' | sed -ne '/^(qqq)$/h;/[0-9]$/{;G;s/\n/ /;p;}' aaa 111 (qqq) bbb 222 (qqq) $
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: can't remove directory Next: how to remove non printing characters |