Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

why the perl one-liner not run with variable input files

Posted on 2009-07-10
8
Medium Priority
?
278 Views
Last Modified: 2012-05-07
Have the following code block
set WKDIR=D:\TEMP\
set _out1=%WKDIR%\test2.txt
set _in1=%WKDIR%\test1.txt
perl -lne "$lines{ $_ }++; END{ print for sort keys %lines }"  %_in1% > %_out1%
I got the error:
----
Missing right curly or square bracket at -e line 1, at end of line
syntax error at -e line 1, at EOF
Execution of -e aborted due to compilation errors.
----------------
but when I did the following
----------------
d:
cd D:\TEMP
perl -lne "$lines{ $_ }++; END{ print for sort keys %lines }"  test1.txt > test2.txt
----------------
I can get the right result without errors.
-------------
D:\TEMP>type test1.txt
WWW
AB_C
ABB
ACB
ABB
XYZ
123
-------
0
Comment
Question by:jl66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 480 total points
ID: 24825893
I don't know perl but could this be due to using %lines and then not ending it with another % so it doesn't terminate the variable name?

Steve
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 480 total points
ID: 24825917
Probably not that.... but actually you have an extra \ in there.... one on the end of wkdir and one on beginning of other two...
0
 
LVL 11

Assisted Solution

by:willettmeister
willettmeister earned 200 total points
ID: 24825951
actually you may not have enough remember \ is a special character in perl try this
set WKDIR=D:/TEMP
set _out1=%WKDIR%/test2.txt
set _in1=%WKDIR%/test1.txt

or this
set WKDIR=D:\\TEMP
set _out1=%WKDIR%\\test2.txt
set _in1=%WKDIR%\\test1.txt
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 84

Expert Comment

by:ozo
ID: 24826843
I don't get that error.
Are you sure you are enclosing the command in quotes?
0
 

Author Comment

by:jl66
ID: 24828011
willettmeister, I tried your suggestions. I got the error messages. Also I rtied to run the same perl on different servers, I got the same. What is wrong with that.
Why don't the other one-liners have this kind of issues? ozo, I copied/pasted the code here. The quotes are here.
 
0
 

Author Comment

by:jl66
ID: 24828021
dragon-it, thanks for pointing out this, but it does not make any difference.
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 680 total points
ID: 24828135
The problem is the % in %lines in a batch file.  The % is a special character to batch files, so it gets interpreted along with the closing } and closing ".  This causes the syntax error.  To fix, you need to use two percent signs where you need one.
perl -lne "$lines{ $_ }++; END{ print for sort keys %%lines }"  %_in1% > %_out1%

Open in new window

0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 640 total points
ID: 24828136
Is this running from a .bat file?
What if you try


set WKDIR=D:\TEMP\
set _out1=%WKDIR%\test2.txt
set _in1=%WKDIR%\test1.txt
set lines=%lines
perl -lne "$lines{ $_ }++; END{ print for sort keys %lines% }"  %_in1% > %_out1%


or
perl -lne "$lines{ $_ }++; END{ print for sort keys %%lines }"  %_in1% > %_out1%
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question