Sponsored Content
Top Forums Shell Programming and Scripting Piping and assigning output to a variable in Perl Post 302315277 by Raynon on Tuesday 12th of May 2009 03:37:08 AM
Old 05-12-2009
Hi KevinADC,

What i am trying to do here is to simply perform the following unix command.
To list those files which matches the terms *$tester*st* and grab the latest file and assign it to a variable name ST_file.
Can you help ?

Code:
set ST_file = `ls -rt *$tester*st*|tail -1`

Re-writing the code

Code:
#!/usr/local/bin/perl
#use strict;
use warnings;
use File::stat;

$[ = 1;
my $tester = "HP100";
my $TEMP = "/mydir/scripts";
my @file_match = (<*$tester*st*>);
for ( $count = 1 ; $count <= $#file_match ; $count++ ) {
        open (FILE_MATCHED,"< $file_match[$count]");
        open (LIST,">> $TEMP/list");
        print LIST "$file_match[$count]\n";
        my @STAT = stat(FILE_MATCHED);
        push (my @time_stamp , $STAT[10]);
        print LIST "$file_match[$count] $STAT[10]\n";
        close (LIST);
        close (FILE_MATCHED);
   
}
my @sorted = sort { $a <=> $b } my @time_stamp;
open (LIST, "< $TEMP/list");
        while ( $line=<LIST> ) {
                my @Fld = split(' ', $line);
                print "$#sorted\n";
                if ( $Fld[2] == $sorted[$#sorted] ) {
                        my $ST_file = sprintf{"%s",$Fld[1]};
                }
        };
close (LIST);
print "$ST_file\n";


Last edited by Raynon; 05-13-2009 at 06:29 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning output of command to a variable

Hi, I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string. Contents of test.txt --> This is a test var1="`head -n 1 test.txt`" echo $var1 (This is a... (5 Replies)
Discussion started by: oma04
5 Replies

2. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

3. Shell Programming and Scripting

Assigning output of command to a variable in shell

hi, I want to assign find command result into some temporary variable: jarPath= find /opt/lotus/notes/ -name $jarFile cho "the jar path $jarPath" where jarPath is temporary variable. Can anybody help on this. Thanks in advance ----Sankar (6 Replies)
Discussion started by: sankar reddy
6 Replies

4. Shell Programming and Scripting

Assigning output to a variable

I am new to unix shell scripting. I was trying to convert each lines in a file to upper case. I know how to convert the whole file. But here i have to do line by line. I am getting it in the below mentioned script #!/bin/bash #converting lower to upper in a file #tr "" "" <file1... (3 Replies)
Discussion started by: jpmena
3 Replies

5. Shell Programming and Scripting

Assigning output of a command to variable

When I run time -p <command>, it outputs: real X.XX user X.XX sys X.XXwhere X.XX is seconds. How I can take just that first number output, the seconds of real time, and assign that to a variable? (9 Replies)
Discussion started by: jeriryan87
9 Replies

6. Shell Programming and Scripting

assigning SED output to a variable = trouble!

i'm on a Mac running BSD unix. i have a script in which i ask the user to input the name of a mounted volume. i then call SED to substitute backslashes and spaces in place of the spaces. that looks like this: echo "Enter the name of the volume" read Volume echo "You've chosen \"$Volume\""... (7 Replies)
Discussion started by: hungryd
7 Replies

7. Shell Programming and Scripting

piping output from PHP file into variable

Hi. I have a script like so: #!/bin/bash download='php /var/www/last.php' echo $download if $downloadHow do I pipe the output of the php file into a variable, as when i run the if statement, it just echos the file output to the screen and does not actually consider the output (it will be... (2 Replies)
Discussion started by: daydreamer
2 Replies

8. Shell Programming and Scripting

Assigning output from awk to variable

I have a script whose contents are as below result= awk 's=100 END {print s }' echo "The result is" $result The desired output is The result is 100 My script is running without exiting and i am also not getting the desired output. Please help (5 Replies)
Discussion started by: bk_12345
5 Replies

9. Shell Programming and Scripting

Oneliner ---split string to character by piping shell output to perl

Hello, I was trying to split a string to characters by perl oneliner. echo "The quick brown fox jumps over the lazy dog" | perl -e 'split // ' But did not work as with bash script pipe: echo "The quick brown fox jumps over the lazy dog" | fold -w1 | sort | uniq -ic 8 1 T 1... (6 Replies)
Discussion started by: yifangt
6 Replies

10. Shell Programming and Scripting

Assigning bc output to a variable

I'm converting decimal to integer with bc, and I'd like to assign the integer output from bc to a variable 'val'. E.g. In the code below: If b is 5000.000, lines 6 and 8 will output: 5000 (5000.000+0.5)/1 | bc I'd like val to take the value 5000 though, rather than 5000.000 Does someone... (3 Replies)
Discussion started by: pina
3 Replies
Statistics::Test::RandomWalk(3pm)			User Contributed Perl Documentation			 Statistics::Test::RandomWalk(3pm)

NAME
Statistics::Test::RandomWalk - Random Walk test for random numbers SYNOPSIS
use Statistics::Test::RandomWalk; my $tester = Statistics::Test::RandomWalk->new(); $tester->set_data( [map {rand()} 1..1000000] ); my $no_bins = 10; my ($quant, $got, $expected) = $tester->test($no_bins); print $tester->data_to_report($quant, $got, $expected); DESCRIPTION
This module implements a Random Walk test of a random number generator as outlined in Blobel et al (Refer to the SEE ALSO section). Basically, it tests that the numbers "[0,1]" generated by a random number generator are distributed evenly. It divides "[0,1]" into "n" evenly sized bins and calculates the number of expected and actual random numbers in the bin. (In fact, this counts the cumulated numbers, but that works the same.) METHODS
new Creates a new random number tester. set_rescale_factor The default range of the random numbers [0, 1) can be rescaled by a constant factor. This method is the setter for that factor. rescale_factor Returns the current rescaling factor. set_data Sets the random numbers to operate on. First argument must be either an array reference to an array of random numbers or a code reference. If the first argument is a code reference, the second argument must be an integer "n". The code reference is called "n"-times and its return values are used as random numbers. The code reference semantics are particularly useful if you do not want to store all random numbers in memory at the same time. You can write a subroutine that, for example, generates and returns batches of 100 random numbers so no more than 101 of these numbers will be in memory at the same time. Note that if you return 100 numbers at once and pass in "n=50", you will have a sequence of 5000 random numbers. test Runs the Random Walk test on the data that was previously set using "set_data". First argument must be the number of bins. Returns three array references. First is an array of quantiles. If the number of bins was ten, this (and all other returned arrays) will hold ten items. Second are the determined numbers of random numbers below the quantiles. Third are the expected counts. data_to_report From the data returned by the "test()" method, this method creates a textual report and returns it as a string. Do not forget to pass in the data that was returned by "test()" or use the "test_report()" method directly if you do not use the data otherwise. SUBROUTINES
n_over_k Computes "n" over "k". Uses Perl's big number support and returns a Math::BigFloat object. This sub is memoized. SEE ALSO
Math::BigFloat, Memoize, Params::Util Random number generators: Math::Random::MT, Math::Random, Math::Random::OO, Math::TrulyRandom, "/dev/random" where available Statistics::Test::Sequence The algorithm was taken from: (German) Blobel, V., and Lohrmann, E. Statistische und numerische Methoden der Datenanalyse. Stuttgart, Leipzig: Teubner, 1998 AUTHOR
Steffen Mueller, <smueller@cpan.org> COPYRIGHT AND LICENSE
Copyright (C) 2007-2010 by Steffen Mueller This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6 or, at your option, any later version of Perl 5 you may have available. perl v5.10.1 2011-01-01 Statistics::Test::RandomWalk(3pm)
All times are GMT -4. The time now is 12:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy