Splitting and joining {61 0} {141 0} {70 0} {62 0}.

This is a discussion on Splitting and joining {61 0} {141 0} {70 0} {62 0}. within the shell forums in Operating Systems category; On Aug 25, 6:50 pm, Kuhl wrote: > Hi, all: > > (1) I have a file curly_brace_pairs.txt like shown below: > > {61 0} {141 0} {70 0} {62 0} {142 0} {71 0} {63 0} {63 63} {143 0} > > I wish to split it into lines, while each line has only one pair of > curly brace, such like: > {61 0} > {141 0} > {70 0} > {62 0} > {142 0} > {71 0} > {63 0} > {63 63} > {143 0} > > I tried several ways to do it, but never succeeded: > In a c-shell (or tcsh) and from it's command line you could do ...

Go Back   Database Forum > Operating Systems > shell

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #11  
Old 08-27-2008, 09:52 AM
Default Re: Splitting and joining {61 0} {141 0} {70 0} {62 0}.

On Aug 25, 6:50 pm, Kuhl wrote:
> Hi, all:
>
> (1) I have a file curly_brace_pairs.txt like shown below:
>
> {61 0} {141 0} {70 0} {62 0} {142 0} {71 0} {63 0} {63 63} {143 0}
>
> I wish to split it into lines, while each line has only one pair of
> curly brace, such like:
> {61 0}
> {141 0}
> {70 0}
> {62 0}
> {142 0}
> {71 0}
> {63 0}
> {63 63}
> {143 0}
>
> I tried several ways to do it, but never succeeded:
>


In a c-shell (or tcsh) and from it's command line you could do this:

Method-A:

sed -e ' \
s/} /&\\
/g' < yourfile

Note: Make sure nothing follows the backslashes not even a space or a
TAB or any character because you are escaping the newline. The two
backslashes are there since one required the sed command itself while
the other one is used to escape the newline.


Method-B:
This is in case you dont want to embed a hardcoded newline.

sed -e 'G;:a' -e 's/} \({.*\)\(\n\)/}\2\1\2/;ta' -e 's/.$//' <
yourfile
Reply With Quote
  #12  
Old 08-29-2008, 10:40 AM
Default Re: Splitting and joining {61 0} {141 0} {70 0} {62 0}.

Hi, thank you everyone for so many solutions. :-)
Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 12:46 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.