Home: Perl Programming Help: Beginner:
?????



zoomer003
Novice

Jun 8, 2010, 1:30 PM


Views: 2180
?????

hey guys how would you write this command in perl script

C:\GPS\grep.exe FTS, EVKCONFIGFILE.txt -> GPRS.xls

little background, grep.exe is a program that searches EVKCONFIGFILE.txt for FTS, and paste everysingle line that has FTS, in GPRS.xls

i have tried this method

@grep = ('C:\GPS\grep.exe', 'FTS,', 'EVKCONFIGFILE.txt', '->', 'GPRS.xls');
system(@grep) == 0 or die "system @grepfailed: $?";


FishMonger
Veteran / Moderator

Jun 8, 2010, 3:53 PM


Views: 2175
Re: [zoomer003] ?????

There are several ways to accomplish this task. This is the most likely method I'd use, which doesn't rely on a system call.


Code
open my $fh, '<', 'EVKCONFIGFILE.txt' 
or die "failed to open 'EVKCONFIGFILE.txt' $!";

my @fts = grep(/FTS/, <$fh>);
print @fts;



zoomer003
Novice

Jun 9, 2010, 8:04 AM


Views: 2162
Re: [FishMonger] ?????

hey thank you .. but just a little problem the method you gave me is printing the output on the cmd screen but i want it to print it in Excel worksheet .. how would i do that
Attachments: cmd screen.JPG (244 KB)


zoomer003
Novice

Jun 9, 2010, 8:25 AM


Views: 2160
Re: [FishMonger] ?????

Perfect. I got it Thanks alot!


FishMonger
Veteran / Moderator

Jun 9, 2010, 8:35 AM


Views: 2158
Re: [zoomer003] ?????

First, you should understand that you were not creating an Excel file. You were creating a plain text file which you happen to view in Excel.

If you want a plain text file then either use command line input/output redirection to send the output to a file or open another filehandle in the script and send the output to that filehandle instead of STDOUT.

If you want to create a true Excel binary file, then you need to use the Spreadsheet::WriteExcel module.
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.37/lib/Spreadsheet/WriteExcel.pm