?
Solved

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

Posted on 2009-07-10
8
Medium Priority
?
277 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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

765 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