Re: How to deal with "{" in system("...command..."); ?
- From: xhoster@xxxxxxxxx
- Date: 14 Aug 2008 03:00:31 GMT
Kuhl <chen_zhitao@xxxxxxxxx> wrote:
But there's another command which also works directly in shell, but
failed in Perl command system("..."); that is:
sed "s/ \.\.\.\.\.\.\.\./ /" file_a > file_b
I want to replace all strings of one blank followed by 8 dots
( ........) with just one blank ( ). It works correctly in the shell.
But If I try to run it in Perl like following:
system("sed 's/ \.\.\.\.\.\.\.\./ /' file_a > file_b");
then it seems \. is not interpreted as one dot, but interpreted as any
one character. So everywhere there are 8 characters following a blank,
they are all replaced.
There are some things you should try to to do debug your own programs. One
of the things to try is to print the string you think you are running, by
replacing system with print.
print("sed 's/ \.\.\.\.\.\.\.\./ /' file_a > file_b");
The output is:
sed 's/ ......../ /' file_a > file_b
The backslashes are special to perl's double-quotes, and so the backslashes
are getting eaten be perl and are not making it to sed.
You could use single quotes instead of double quotes, but those would
conflict with the literal single quotes around the sed expression. So
you can use perl's choose-your-own-adventure quoting style:
print(q{sed 's/ \.\.\.\.\.\.\.\./ /' file_a > file_b});
Or the here-doc style quotes:
print <<END;
sed 's/ \.\.\.\.\.\.\.\./ /' file_a > file_b
END
What's more, I think writing \.\.\.\.\.\.\.\. is not a good way.
There's perhaps a better and shorter format of this command.
As long as you are using sed to do the processing, then this between
you and sed. This is the wrong forum for that.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
.
- References:
- Prev by Date: Re: How to solve the issue that \. is interpreted as any character in system("sed ... "); ?
- Next by Date: Re: How to deal with "{" in system("...command..."); ?
- Previous by thread: Re: How to deal with "{" in system("...command..."); ?
- Next by thread: Re: How to deal with "{" in system("...command..."); ?
- Index(es):
Relevant Pages
|