| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
|
| Hi, all: This topic is a follow up of the previous post "Splitting and joining {61 0} {141 0} {70 0} {62 0}." of me. To avoid from being too deprioritized to be displayed on the page, I post it as a new topic now. Thank you everyone that both splitting and joining already have solutions now. Joining was already discussed yesterday. Let's talk about splitting now. Both the two ways below work perfectly in splitting: nawk 'BEGIN{ RS="{" } NR>1 {print "{"$0}' curly_brace_pairs.txt cat curly_brace_pairs.txt | perl -040pe'$\=/}/?"\n":""' About the second approach, I have a further question. I can only write a separate Perl program. I don't know how to run a Perl command directly in shell. So I don't understand what -040pe'$\=/}/?"\n":""' means. The manual page of perl (man perl in my system) does not show how to use it. I have never found any text book showing this topic either. Would you please give me a suggestion on how to learn the method of running perl commands directly in Shell? Learning is my next step. At this moment, if this is easy, then would you please give the answer of what -040pe'$\=/}/?"\n":""' means? Thanks. |
|
#2
|
| On Wednesday 27 August 2008 13:56, Kuhl wrote: > Learning is my next step. At this moment, if this is easy, then would > you please give the answer of what -040pe'$\=/}/?"\n":""' means? Read the line using space (octal 40) as input record separator. This way, perl will read a series of "records" like this: {61 0} {141 0} .... If the current "record" contains "}" (that is, is even), assign "\n" to the output record separator ($\); otherwise, assign the empty string. That has the problem that it prints an extra newline at the end. That could have been written also (among dozens of other ways), with no added newline: perl -pe 's/(?<=}) (?={)/\n/g' curly_brace_pairs.txt perl -ne 'print join "\n", split /(?<=}) (?={)/' curly_brace_pairs.txt -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome. |
|
#3
|
| Kuhl wrote: > So I don't understand what -040pe'$\=/}/?"\n":""' means. The manual > page of perl (man perl in my system) does not show how to use it. I > have never found any text book showing this topic either. # man perlrun |
|
#4
|
| Kuhl wrote: > So I don't understand what -040pe'$\=/}/?"\n":""' means. The manual > page of perl (man perl in my system) does not show how to use it. I > have never found any text book showing this topic either. .... and # man perlvar |
|
#5
|
| Hi, thank you everyone for the solutions. :-) |
![]() |
| Thread Tools | |
| Display Modes | |