473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Unable to match a backslash inside system command

nithinpes
410 Expert 256MB
I will boil down my exact requirement to this: I should print out lines that do not contain semi-colon, backslash and closing parentheses. The following one -liner works fine.
Expand|Select|Wrap|Line Numbers
  1. perl -ne "unless(/[\\);]/) {print}" in.txt > out.txt
  2.  
Consider the following sample data:
Expand|Select|Wrap|Line Numbers
  1. Msg_create(….); \
  2. PSLogI18N\
  3. Free( ….) 
  4. eweqwdeqwe;
  5. erwerwfrrfreer)
  6. rwerttrwerterter\
  7. rtwert)
  8. et
  9. er
  10. te
  11. t
  12. wwwwwwwwwwwwwww\\
  13. erwerrwerr  ;
  14.  
But if I use the same one-liner inside a system() command in a script, backslash(\) will not be matched by the regex. Lines containing backslash will be printed out to out.txt.
Expand|Select|Wrap|Line Numbers
  1. system("perl -ne \"unless(/[\\);]/) {print}\" in.txt > out.txt");
  2.  
This is quite puzzling! Even I tried putting backslash within \Q and \E and using reverse quotes and exec() instead of system command. Got the same results :(
Mar 10 '09 #1
4 3592
KevinADC
4,059 Expert 2GB
try with 4 backslashes:

[\\\\);]

My thinking is that you have to escape two of them for the shell first, then you end up with [\\);] for perl to work with.
Mar 10 '09 #2
nithinpes
410 Expert 256MB
Yes, you are right. It worked :)

Thanks,
Nithin
Mar 10 '09 #3
KevinADC
4,059 Expert 2GB
ahhhh..... lucky guess then. You're welcome. Kind of odd though to use a perl script to run a perl one-liner from the shell. Why not just write it all in the perl script?
Mar 10 '09 #4
nithinpes
410 Expert 256MB
In my script I would be parsing hundreds of files. The input and output filenames would be variables. I prefer writing it all in the perl script, but used this approach to reduce few lines (open & close statements). Came across this issue and wanted to know why..
Mar 11 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this...
0
by: Pankaj Jain | last post by:
Hi All, I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A is exposed to client through remoting on Http...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
32
by: Licheng Fang | last post by:
Basically, the problem is this: 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: 'oneself' The Python regular expression...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.