| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#11
|
| On Aug 25, 6:50 pm, Kuhl > 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 |
|
#12
|
| Hi, thank you everyone for so many solutions. :-) |
![]() |
| Thread Tools | |
| Display Modes | |