![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl: How to convert xxx@dom.ain.com to domaincom | Juha | Shell Programming and Scripting | 6 | 04-30-2008 08:09 AM |
| convert the below perl sript to shell script | mail2sant | Shell Programming and Scripting | 1 | 04-04-2008 01:36 PM |
| awk to perl convert | jaganadh | Shell Programming and Scripting | 2 | 12-11-2007 11:11 AM |
| Sample Unix script file to convert .xml to .csv | srinivasaphani | Shell Programming and Scripting | 4 | 08-27-2007 10:04 AM |
| how to convert unix .ksh script to windows .batch script | 2.5lt V8 | Shell Programming and Scripting | 1 | 11-28-2006 12:52 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
convert unix script to perl
Hi,
I have these lines in a unix script: FILEONE = /<filepath1>/<filename1.txt> FILENEW = /<filepath2>/<filename2.txt> head -5 $FILEONE | sed '1d' > $FILENEW PARAM1 = `cat $FILENEW | awk '{print $2;}' ` echo "Param1 Value: $PARAM1" What's the correct syntax of the above lines if same logic is used on perl? my $FILEONE = "/<filepath1>/<filename1.txt>"; my $FILENEW = "/<filepath2>/<filename2.txt>"; `head -5 $FILEONE | sed '1d' > $FILENEW`; my $PARAM1 = `cat \$FILENEW | awk '\{print $2;\}' `; print ("Param1 Value:" . $PARAM1 ."\n"); Please advise if correct or how to better. Thanks |
|
||||
|
Quote:
Code:
my $file1 = "/path/to/file1";
my $file2 = "/path/to/file2";
open (R, $file1) || die "Could not open $file1: $!\n";
open (W, ">$file2") || die "Could not open $file2: $!\n";
while (<R>) {
print W unless $. == 1;
last if $. == 5;
}
close R;
close W;
Quote:
Code:
my @g;
while (<R>) {
my @f = split;
push @g, $f[1]; # array indices are zero-based, so this is the second field
}
print(join (" ", @g), "\n");
If you want to merge this with the first loop over file1, you can do something like Code:
print W if (2..5); # take out the "last" my @f = split; push @g, $f[1]; Last edited by era; 03-25-2008 at 01:47 PM.. Reason: Merging the two loops; fix indexing error (duh) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|