Running Perl command directly in shell

This is a discussion on Running Perl command directly in shell within the shell forums in Operating Systems category; 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 ...

Go Back   Database Forum > Operating Systems > shell

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-27-2008, 08:56 AM
Default Running Perl command directly in shell

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.
Reply With Quote
  #2  
Old 08-27-2008, 09:34 AM
Default Re: Running Perl command directly in shell

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.
Reply With Quote
  #3  
Old 08-27-2008, 10:17 AM
Default Re: Running Perl command directly in shell

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
Reply With Quote
  #4  
Old 08-27-2008, 10:19 AM
Default Re: Running Perl command directly in shell

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
Reply With Quote
  #5  
Old 08-29-2008, 10:33 AM
Default Re: Running Perl command directly in shell

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


Thread Tools
Display Modes



All times are GMT -4. The time now is 09:30 AM.


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.