why do I have to pipe perl output into a new perl commandPipe output and capture exit status in BashHow do I set a variable to the output of a command in Bash?Why does modern Perl avoid UTF-8 by default?Setting an environment variable before a command in bash not working for second command in a pipeSome GNUPlot terminals work from command line, but not when called from Perl (piping)Parsing command output from bashSpecific pipe command in Ubuntu's shell handling in CMulti-line, double quoted string triggers history expansion on subsequent single-quoted commands it gets piped toPerl module File:Slurp with STDIN pipedPerl command works on command line but not within a bash script
How is char processed in math mode?
Why is “deal 6 damage” a legit phrase?
integration of absolute value
Coworker mumbles to herself when working, how to ask her to stop?
Adding a (stair/baby) gate without facing walls
Password management for kids - what's a good way to start?
No Shirt, No Shoes, Service
Should I intervene when a colleague in a different department makes students run laps as part of their grade?
How to litter train a cat if both my husband and I work away from home all day?
Best Ergonomic Design for a handheld ranged weapon
Is it unprofessional to mention your cover letter and resume are best viewed in Chrome?
Would people understand me speaking German all over Europe?
Gold Battle KoTH
How to structure presentation to avoid getting questions that will be answered later in the presentation?
Russian pronunciation of /etc (a directory)
Reducing the time for rolling hash
How do discovery writers hibernate?
May a hotel provide accommodation for fewer people than booked?
What does 「ちんちんかいかい」 mean?
How can flights operated by the same company have such different prices when marketed by another?
A conjectural trigonometric identity
What are these hats and the function of those wearing them? worn by the Russian imperial army at Borodino
Why do we need a voltage divider when we get the same voltage at the output as the input?
In the Schrödinger equation, can I have a Hamiltonian without a kinetic term?
why do I have to pipe perl output into a new perl command
Pipe output and capture exit status in BashHow do I set a variable to the output of a command in Bash?Why does modern Perl avoid UTF-8 by default?Setting an environment variable before a command in bash not working for second command in a pipeSome GNUPlot terminals work from command line, but not when called from Perl (piping)Parsing command output from bashSpecific pipe command in Ubuntu's shell handling in CMulti-line, double quoted string triggers history expansion on subsequent single-quoted commands it gets piped toPerl module File:Slurp with STDIN pipedPerl command works on command line but not within a bash script
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to remove whitespace between back-tick (x60) and word characters, inside of a perl script that performs many other regex substitutions. If I print the result of the earlier substitutions to the bash shell and then pipe into a new perl invocation, it works. But inside a single perl invocation, it doesn't. In the example below, the third line (a single perl command) does not work whereas the fourth line (two separate commands) does work.
printf '%b' 'Well, `n he said it n'
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g;' ; echo
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g;' | perl -p -e 'use strict; use warnings; s|([x60])s*(w)|$1$2|g;'; echo
Why does it not work inside a single perl invocation? I thought we were supposed to avoid multiple or nested pipes (subshells).
This is perl 5, version 18 and GNU bash, version 3.2.57(1) in BSD unix.
bash perl recursion pipe string-substitution
add a comment |
I want to remove whitespace between back-tick (x60) and word characters, inside of a perl script that performs many other regex substitutions. If I print the result of the earlier substitutions to the bash shell and then pipe into a new perl invocation, it works. But inside a single perl invocation, it doesn't. In the example below, the third line (a single perl command) does not work whereas the fourth line (two separate commands) does work.
printf '%b' 'Well, `n he said it n'
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g;' ; echo
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g;' | perl -p -e 'use strict; use warnings; s|([x60])s*(w)|$1$2|g;'; echo
Why does it not work inside a single perl invocation? I thought we were supposed to avoid multiple or nested pipes (subshells).
This is perl 5, version 18 and GNU bash, version 3.2.57(1) in BSD unix.
bash perl recursion pipe string-substitution
add a comment |
I want to remove whitespace between back-tick (x60) and word characters, inside of a perl script that performs many other regex substitutions. If I print the result of the earlier substitutions to the bash shell and then pipe into a new perl invocation, it works. But inside a single perl invocation, it doesn't. In the example below, the third line (a single perl command) does not work whereas the fourth line (two separate commands) does work.
printf '%b' 'Well, `n he said it n'
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g;' ; echo
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g;' | perl -p -e 'use strict; use warnings; s|([x60])s*(w)|$1$2|g;'; echo
Why does it not work inside a single perl invocation? I thought we were supposed to avoid multiple or nested pipes (subshells).
This is perl 5, version 18 and GNU bash, version 3.2.57(1) in BSD unix.
bash perl recursion pipe string-substitution
I want to remove whitespace between back-tick (x60) and word characters, inside of a perl script that performs many other regex substitutions. If I print the result of the earlier substitutions to the bash shell and then pipe into a new perl invocation, it works. But inside a single perl invocation, it doesn't. In the example below, the third line (a single perl command) does not work whereas the fourth line (two separate commands) does work.
printf '%b' 'Well, `n he said it n'
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g;' ; echo
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
printf '%b' 'Well, `n he said it n' | perl -p -e 'use strict; use warnings; s|n||g;' | perl -p -e 'use strict; use warnings; s|([x60])s*(w)|$1$2|g;'; echo
Why does it not work inside a single perl invocation? I thought we were supposed to avoid multiple or nested pipes (subshells).
This is perl 5, version 18 and GNU bash, version 3.2.57(1) in BSD unix.
bash perl recursion pipe string-substitution
bash perl recursion pipe string-substitution
asked Mar 26 at 22:34
Jacob WegelinJacob Wegelin
1531 silver badge6 bronze badges
1531 silver badge6 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Because your perl -p
is splitting on newlines, your first perl removes them, and the second one sees everything as if it were on one line.
printf '%b' 'Well, `n he said it n' | perl -p0 -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
By telling perl to slurp it all in at once, the first s
can remove the new lines, and the second will remove the spaces after your quote.
-0
doesn't actually enable slurp mode; use-0777
for that.
– ikegami
Mar 26 at 23:53
@Tanktalus, this is very helpful. Where are -0 and -0777 documented? How does syntax change to perform this in a perl script, rather than a command-line invocation?
– Jacob Wegelin
Mar 27 at 1:52
@JacobWegelin see perldoc.perl.org/perlrun.html
– Shawn
Mar 27 at 2:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367141%2fwhy-do-i-have-to-pipe-perl-output-into-a-new-perl-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Because your perl -p
is splitting on newlines, your first perl removes them, and the second one sees everything as if it were on one line.
printf '%b' 'Well, `n he said it n' | perl -p0 -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
By telling perl to slurp it all in at once, the first s
can remove the new lines, and the second will remove the spaces after your quote.
-0
doesn't actually enable slurp mode; use-0777
for that.
– ikegami
Mar 26 at 23:53
@Tanktalus, this is very helpful. Where are -0 and -0777 documented? How does syntax change to perform this in a perl script, rather than a command-line invocation?
– Jacob Wegelin
Mar 27 at 1:52
@JacobWegelin see perldoc.perl.org/perlrun.html
– Shawn
Mar 27 at 2:08
add a comment |
Because your perl -p
is splitting on newlines, your first perl removes them, and the second one sees everything as if it were on one line.
printf '%b' 'Well, `n he said it n' | perl -p0 -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
By telling perl to slurp it all in at once, the first s
can remove the new lines, and the second will remove the spaces after your quote.
-0
doesn't actually enable slurp mode; use-0777
for that.
– ikegami
Mar 26 at 23:53
@Tanktalus, this is very helpful. Where are -0 and -0777 documented? How does syntax change to perform this in a perl script, rather than a command-line invocation?
– Jacob Wegelin
Mar 27 at 1:52
@JacobWegelin see perldoc.perl.org/perlrun.html
– Shawn
Mar 27 at 2:08
add a comment |
Because your perl -p
is splitting on newlines, your first perl removes them, and the second one sees everything as if it were on one line.
printf '%b' 'Well, `n he said it n' | perl -p0 -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
By telling perl to slurp it all in at once, the first s
can remove the new lines, and the second will remove the spaces after your quote.
Because your perl -p
is splitting on newlines, your first perl removes them, and the second one sees everything as if it were on one line.
printf '%b' 'Well, `n he said it n' | perl -p0 -e 'use strict; use warnings; s|n||g; s|([x60])s*(w)|$1$2|g;' ; echo
By telling perl to slurp it all in at once, the first s
can remove the new lines, and the second will remove the spaces after your quote.
answered Mar 26 at 22:42
TanktalusTanktalus
17.8k4 gold badges34 silver badges63 bronze badges
17.8k4 gold badges34 silver badges63 bronze badges
-0
doesn't actually enable slurp mode; use-0777
for that.
– ikegami
Mar 26 at 23:53
@Tanktalus, this is very helpful. Where are -0 and -0777 documented? How does syntax change to perform this in a perl script, rather than a command-line invocation?
– Jacob Wegelin
Mar 27 at 1:52
@JacobWegelin see perldoc.perl.org/perlrun.html
– Shawn
Mar 27 at 2:08
add a comment |
-0
doesn't actually enable slurp mode; use-0777
for that.
– ikegami
Mar 26 at 23:53
@Tanktalus, this is very helpful. Where are -0 and -0777 documented? How does syntax change to perform this in a perl script, rather than a command-line invocation?
– Jacob Wegelin
Mar 27 at 1:52
@JacobWegelin see perldoc.perl.org/perlrun.html
– Shawn
Mar 27 at 2:08
-0
doesn't actually enable slurp mode; use -0777
for that.– ikegami
Mar 26 at 23:53
-0
doesn't actually enable slurp mode; use -0777
for that.– ikegami
Mar 26 at 23:53
@Tanktalus, this is very helpful. Where are -0 and -0777 documented? How does syntax change to perform this in a perl script, rather than a command-line invocation?
– Jacob Wegelin
Mar 27 at 1:52
@Tanktalus, this is very helpful. Where are -0 and -0777 documented? How does syntax change to perform this in a perl script, rather than a command-line invocation?
– Jacob Wegelin
Mar 27 at 1:52
@JacobWegelin see perldoc.perl.org/perlrun.html
– Shawn
Mar 27 at 2:08
@JacobWegelin see perldoc.perl.org/perlrun.html
– Shawn
Mar 27 at 2:08
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367141%2fwhy-do-i-have-to-pipe-perl-output-into-a-new-perl-command%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown