Sponsored Content
Top Forums Shell Programming and Scripting How to sort list of directories in descending order in perl? Post 303042943 by venkatesh on Monday 13th of January 2020 02:34:41 AM
Old 01-13-2020
How to sort list of directories in descending order in perl?

Hi,
I have a problem . I have few directories like inpTDT_1, inpTDT_2, inpTDT_3 and so on inside HOME directory . In one of my perl script (which is in my HOME), the above directories like inpTDT_1, inpTDT_2, inpTDT_3 are sorting out in an order So I wanted to sort all the inpTDT_1, inpTDT_2, inpTDT_3 and so on directories in Descending order . based on _* Value .How can I do that ???
Please give fast Response.

FYI,
Code:
foreach $regress_dir (<$wdir/regress_*>) {
        if (-e "$regress_dir/$vdb_dir") {
            $cov_dirs = sprintf "$regress_dir/$vdb_dir $cov_dirs";
            print "Regress_directories are $cov_dirs and loop_variable is $regress_dir \n";
} else {}


Last edited by RavinderSingh13; 01-13-2020 at 05:08 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to see disk usage in descending order

What is the command used by sysadmin to see the disk used by the users in descending order of their disk usage? (8 Replies)
Discussion started by: asutoshch
8 Replies

2. Shell Programming and Scripting

Ascending & Descending order numbers

Dear All, I have below attached file in which i have many nos, i want the last ascending order nos. The brief description is given below. File 315 381 432 315 381 432 315 381 432 315 381 432 315 381 432 (6 Replies)
Discussion started by: pravani1
6 Replies

3. UNIX for Dummies Questions & Answers

Help - Find command with list of files modified descending Order

Hi, I would like to know the command to get the files order in descending order with "FIND" command. Appreciate your help Thanks (4 Replies)
Discussion started by: TonySolarisAdmi
4 Replies

4. UNIX for Dummies Questions & Answers

how to list descending order

Hi, I want to short descending all the files according to their size.Please help me.. (1 Reply)
Discussion started by: jyotidas
1 Replies

5. Shell Programming and Scripting

How to list all the directories, sub directories in a mount along with size in ascending order?

Hi , I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In a particular mount, have to list all the directories and sub directories along with size of the directory and sub directory in ascending order. Please help me in this regard and many... (4 Replies)
Discussion started by: nmakkena
4 Replies

6. Shell Programming and Scripting

Unable to get the correct sort order in perl.

Hi, I have created the hash. %hash; @arr1 = qw(Dealnum AdminStatus adminReason effFrom effTo); @arr2 = qw(121212121 YES 1992-06-19T05:14:27 ); @hash{@arr1}=@arr2; foreach(sort keys %hash){ print "$_ ---- $hash{$_}\n"; } The output i got like this: C:\strawberry\perl\bin>perl... (1 Reply)
Discussion started by: vanitham
1 Replies

7. Shell Programming and Scripting

Help with sort data based on descending order problem

Input file 9.99331e-13 8.98451e-65 9.98418e-34 7.98319e-08 365592 111669 74942.9 0 Desired output 365592 111669 74942.9 7.98319e-08 1.99331e-13 6.98418e-34 (2 Replies)
Discussion started by: perl_beginner
2 Replies

8. Shell Programming and Scripting

script for remove descending order number

hi all i want to remove some descending order number example : 1 100 200 135.00 Gk_wirs 1 1 100 200 136.00 Gk_wirs 50 1 110 210 138.00 Gk_wirs 60 1 100 200 136.00 Gk_wirs 57 ----> how to remove... (6 Replies)
Discussion started by: nithyanandan
6 Replies

9. Shell Programming and Scripting

Sort names in a list by order of importance

Hi, I have multiple list which is arranged by order of importance. I need to do sorting on these lists based on the last name of the user(initial), if user name does not have initial then first name is initial . Important thing is that the last name in the list is important. If there is two or... (1 Reply)
Discussion started by: pratapsingh
1 Replies

10. UNIX for Dummies Questions & Answers

Sorting a file in descending order when you have 10e- values

Hi, I am trying to sort the following file in descending order of its fourth column. 2 1 363828 -2.423225e-03 3 1 363828 4.132763e-03 3 2 363828 8.150133e-03 4 1 363828 4.126890e-03 I use sort -k4,4g -r input.txt > output.txt ... (1 Reply)
Discussion started by: evelibertine
1 Replies
SCANDIR(3)								 1								SCANDIR(3)

scandir - List files and directories inside the specified path

SYNOPSIS
array scandir (string $directory, [int $sorting_order = SCANDIR_SORT_ASCENDING], [resource $context]) DESCRIPTION
Returns an array of files and directories from the $directory. PARAMETERS
o $directory - The directory that will be scanned. o $sorting_order - By default, the sorted order is alphabetical in ascending order. If the optional $sorting_order is set to SCANDIR_SORT_DESCEND- ING, then the sort order is alphabetical in descending order. If it is set to SCANDIR_SORT_NONE then the result is unsorted. o $context - For a description of the $context parameter, refer to the streams section of the manual. RETURN VALUES
Returns an array of filenames on success, or FALSE on failure. If $directory is not a directory, then boolean FALSE is returned, and an error of level E_WARNING is generated. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.4.0 | | | | | | | $sorting_orderconstants were added. Any nonzero | | | value caused descending order in previous ver- | | | sions. So for all PHP versions, use 0 for ascend- | | | ing order, and 1 for descending order. An option | | | for SCANDIR_SORT_NONE behavior did not exist | | | prior to PHP 5.4.0. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A simple scandir(3) example <?php $dir = '/tmp'; $files1 = scandir($dir); $files2 = scandir($dir, 1); print_r($files1); print_r($files2); ?> The above example will output something similar to: Array ( [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ) Array ( [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ) Example #2 PHP 4 alternatives to scandir(3) <?php $dir = "/tmp"; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } sort($files); print_r($files); rsort($files); print_r($files); ?> The above example will output something similar to: Array ( [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ) Array ( [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ) NOTES
Tip A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen(3) for more details on how to specify the filename. See the "Supported Protocols and Wrappers" for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. SEE ALSO
opendir(3), readdir(3), glob(3), is_dir(3), sort(3). PHP Documentation Group SCANDIR(3)
All times are GMT -4. The time now is 05:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy