Cannot run command line scripts in perl or gawk

 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Cannot run command line scripts in perl or gawk
# 1  
Old 09-20-2010
Cannot run command line scripts in perl or gawk

I originally posted this to a different forum (I am a new Perl user) and realized the error so I will ask here.

I am on a WindowsXP machine trying to run perl and gawk scripts from the command line. I have perl and gawk installed and environment set to C:\perl\bin and cannot get a script to execute from the command line in Windows. The input file is in the same directory as perl.exe. When I try gawk I also am running from cmd.exe with input file in same directory.

The message that I see follows:

"The system cannot find the file specified."

I have checked that C:\Perl\bin;C:\Perl\site\bin are in the environment PATH. I don't see gawk anywhere in there though. Maybe that's a problem. Does anyone have any ideas about what I can change to get perl and gawk to work from the cmd.exe window?

I can run the simple command in perl to check the version number with no errors - 'perl -v'. Maybe that helps.


perl script - "perl -lne 'if ($.<=4) {push @x,$_} else {$x[($.-1)%4] .=" ".(split)[2]} END {print for @x}' inputfilename"
gawk script - "gawk 'NR<5 {a[$2]=$0;next} {a[$2]=a[$2] FS $NF}END {for (i in a) print a[i]|"sort -n"}' inputfilename'
Thanks to all of you. - 10000Springs(BC)

Last edited by 10000springs; 09-20-2010 at 02:14 AM.. Reason: Forgot to add scripts used -duh!
# 2  
Old 09-20-2010
Quote:
Originally Posted by 10000springs
...

The message that I see follows:

"The system cannot find the file specified."

...
perl script - "perl -lne 'if ($.<=4) {push @x,$_} else {$x[($.-1)%4] .=" ".(split)[2]} END {print for @x}' inputfilename"
...
I was thinking that you put "f19" as your input file name, but that doesn't appear to be the case as can be deduced from your post above. "f19" was just a dummy file that I had created on my system to test the script.

Good that you mentioned you are on Windows. Quoting works differently on Windows than on *nix.

The Windows equivalent of my earlier post would be this -

Code:
C:\> type f19
C:\> perl -lne "if ($.<=4) {push @x,$_} else {$x[($.-1)%4] .= \" \".(split)[2]} END {print for @x}" f19

And you'd want to substitute f19 by your input file name.

Note that the main script is enclosed within double quotes, and the inner double quotes are escaped. I don't have Windows anywhere near me right now, so the commands are untested.

HTH,
tyler_durden
# 3  
Old 09-20-2010
Tyler_Durden - Thanks for the speedy reply. I have modified the script to use the double quotes and to escape the other double quotes.

The script does work now! Awesome! Smilie

I did have a bit of a start when I ran it the first time and got an array that was only 4 rows long by tons of columns. Then I remembered that the "4" in the script referenced the number of rows in the input file so I changed that to 65537 so it would match my input file and voila!

I have to do some more studying on all the switches and get more familiar with perl on the command line. It is a lot like awk or sed. Very useful.

I am going to mess with the gawk script to see if it needs a bit of a tweak too.

Thanks a million - 10000Springs(BC)

---------- Post updated at 01:51 PM ---------- Previous update was at 01:09 AM ----------

Well I worked with this a bit last night to get the gawk script running. I was able to make it work but only if I left out the "sort".

From reading a bit of documentation it appears that there is no sort in gawk, it uses asort instead. Even knowing this I haven't been able to get it to fly yet and running without sorting the output gives totally unusable results.

I tried:
gawk script - gawk "NR<5 {a[$2]=$0;next} {a[$2]=a[$2] FS $NF}END {for (i in a) print a[i]|\"sort -n\"}" inputfilename

so that I have replaced the quotes with double-quotes and escaped the quotes around the 'sort -n' part after the pipe. This did not work.

The only way I could execute with on error was to leave the sort after the pipe out of the script.

I will be looking deeper into the asort function in gawk over the next day or two and will post a fix if I find one.

Does anyone have any tips for an alternate method of preserving the sort order of an input in a gawk script?

Thanks for looking. --10000Springs(BC)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run 2 python scripts at the same time side by side on the same line?

Could I run 2 python scripts at the same time side by side output on the same line in this same format but with scripts? from itertools import izip_longest with open("file1") as textfile1, open("file2") as textfile2: for x, y in izip_longest(textfile1, textfile2, fillvalue=""): x =... (4 Replies)
Discussion started by: bigvito19
4 Replies

2. Shell Programming and Scripting

Better way to run this perl command

i'm working with files that are huge in size. over 3GB. and i need to do a lot of pattern matching. I need a way to grep for what i want, using a tool that is available across most unix systems. i initially was gungho about grep, but not all capablities of grep are available on all OSes. so... (10 Replies)
Discussion started by: SkySmart
10 Replies

3. Shell Programming and Scripting

Running Two scripts in a single command line

Hi All, I have two scripts which i want to run in a single command line(or in a single script). And if both the scripts in the main script fail then i want to pass a value to a Application specific utility which will trigger some alert.The value can be anything. Somebody please help.It is... (1 Reply)
Discussion started by: shroh
1 Replies

4. UNIX for Dummies Questions & Answers

Run perl scripts to a distant server!!!!

Hello everybody; I want to run some scripts perl on my windows pc to a distant server linux which i connect to it via putty,I'm just a small beginner and I want just to know if this is possible or not and if you can send me some docs I will really grateful. (1 Reply)
Discussion started by: bassma
1 Replies

5. Shell Programming and Scripting

Run perl script, with command-line options

Hello everyone, I have a perl script which takes various command line options from user like : test.pl -i <input_file> -o <output_file> -d <value> -c <value> Now I have multiple input files in a directory: <input_file_1> <input_file_2> <input_file_3> <input_file_4> ..... .... ...... (6 Replies)
Discussion started by: ad23
6 Replies

6. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

7. Shell Programming and Scripting

Is command line invocation of gnome-terminal to run more than one command possible?

Hello, I am trying to learn how to pass something more than a one-command startup for gnome-terminal. I will give an example of what I'm trying to do here: #! /bin/bash # #TODO write this for gnome and xterm USAGE=" ______________________________________________ ${0##*/} run... (0 Replies)
Discussion started by: Narnie
0 Replies

8. Shell Programming and Scripting

How can I make running gawk scripts more user-friendly in a Windows environment?

I know, and I apologise for using the W word, but I have users asking if they can use my gawk scripts, but I just know they're not going to like using the DOS command line. Is there any way for me to run my gawk scripts from a gui? Even if it's from a web page (html, php, what ever). I do not... (3 Replies)
Discussion started by: jonathanm
3 Replies

9. UNIX for Dummies Questions & Answers

how to write perl substitute command in shell scripts

How to write perl substitute command in shell script without invoking a perl script file seperately. for ex: shell script to relace IT with CSC in a file using perl substitute command. (3 Replies)
Discussion started by: param_it
3 Replies

10. Shell Programming and Scripting

what's the debug command for perl scripts

Hi, Can you please let me know if there's any debug command for perl scripts like set -x for shell scripts (2 Replies)
Discussion started by: dayanandra
2 Replies
Login or Register to Ask a Question