From: vjp2.at on 25 Sep 2009 13:59 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 - = - 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: Marcel Bruinsma on 25 Sep 2009 15:24 Am Freitag, 25. September 2009 19:59, vjp2.at(a)at.BioStrategist.dot.dot.com a écrit : > 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 If awk instead of sed is acceptable: awk '/^[(]/{l=$1;next}{$++NF=l}1' or, if the file contains other lines as well: awk '$1~/^[(][^)]+[)]$/{l=$1;next} l&&$NF~/[0-9]+/{$++NF=l}1' -- printf -v email $(echo \ 155 141 162 143 145 154 142 162 165 151 \ 156 163 155 141 100 171 141 150 157 157 056 143 157 155|tr \ \\\\) # Live every life as if it were your last! #
From: Maxwell Lol on 25 Sep 2009 15:26 vjp2.at(a)at.BioStrategist.dot.dot.com writes: > 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 > Why is sed a requirement?
From: Marcel Bruinsma on 25 Sep 2009 15:31 Am Freitag, 25. September 2009 21:24, Marcel Bruinsma a écrit : > or, if the file contains other lines as well: > > awk '$1~/^[(][^)]+[)]$/{l=$1;next} > l&&$NF~/[0-9]+/{$++NF=l}1' awk 'NF==1&&$1~/^[(][^)]+[)]$/{l=$1;next} l&&$NF~/^[0-9]+$/{$++NF=l}1' -- printf -v email $(echo \ 155 141 162 143 145 154 142 162 165 151 \ 156 163 155 141 100 171 141 150 157 157 056 143 157 155|tr \ \\\\) # Live every life as if it were your last! #
From: Ed Morton on 25 Sep 2009 16:31 On Sep 25, 12:59 pm, vjp2...(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 > 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 Ed.
|
Next
|
Last
Pages: 1 2 3 4 Prev: can't remove directory Next: how to remove non printing characters |