displaying 3 directory listings in 3 separate columns.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting displaying 3 directory listings in 3 separate columns.
# 15  
Old 04-03-2007
This will also work in perl.

Code:
#!/usr/bin/perl

$DIR1 ="dir_1";
$DIR2 ="dir_2";
$DIR3 ="dir_3";
@dir1 = `ls -1 $DIR1`;
@dir2 = `ls -1 $DIR2`;
@dir3 = `ls -1 $DIR3`;

$maxFile = scalar(@dir1);
if($maxFile < scalar(@dir2)){
        $maxFile = scalar(@dir2);
}
if($maxFile < scalar(@dir3)){
        $maxFile = scalar(@dir3);
}
        printf("%20s\t%20s\t%20s\n","$DIR1", "$DIR2", "$DIR3");
        for($i=0;$i<$maxFile;$i++)
        {
        printf("%20s\t%20s\t%20s\n","@dir1[$i]", "@dir2[$i]", "@dir3[$i]");
        }



Thanks,
Mukund Ranjan
# 16  
Old 04-04-2007
thanks munkund ranjan. coincedently i'm going to convert the script i'm writing into perl - once i've learnt the language that is.
# 17  
Old 04-04-2007
If you have Python, here's an alternative
Code:
#!/usr/bin/python
import os
a = os.listdir("/test1")
b = os.listdir("/test2")
c = os.listdir("/test3")
for item in map(None,a,b,c):
     if item[0] == None: item[0] = ''     
     if item[1] == None: item[1] = ''
     if item[2] == None: item[2] = ''
     print "%20s\t%20s\t%20s" % (item[0],item[1],item[2])

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies

2. Shell Programming and Scripting

Separate columns into different text files

Hi I have large text file consisting of five columns. Sample of the file is give below: ed 2-4 12.0 commons that they depended on. मानवों नष्ट किया जिन पर वो आधारित थे। ed 3-1 12.0 Almost E, but would be over. रचना करीब करीब ई तक जाती है, मगर तब तो नाटक ख़त्म हो... (2 Replies)
Discussion started by: my_Perl
2 Replies

3. UNIX for Dummies Questions & Answers

Intersect of two columns in two separate files

Hi, I have a file like this: abc def ghi jkl mno My second file is like this (tab delimited): adsad sdfsdf dfdf wads abc dfdsf sdsf jkl sfsdf dsfds sdfd reor zxczd dsf sff Now, I want the code to report the lines (from file2) which have common strings in column 2 with the first... (4 Replies)
Discussion started by: a_bahreini
4 Replies

4. UNIX for Dummies Questions & Answers

Concatenate two columns and separate by - (minus)

hi all could you please help me to concatenate two colomns and separate them by "-" the two colomns to concatenate are colomuns 1 and 3 of a very bif file clomn 1 is chr, 2 is snp and 3 is bp the new colomn is chr_B input file : 1 rs1111 10583 1 rs1891 10611 1 rs1807 ... (13 Replies)
Discussion started by: biopsy
13 Replies

5. Shell Programming and Scripting

Separate into columns

Hi all I have following kind of data in a file but non separated ESR1 PA156 leflunomide PA450192 CHST3 PA26503 docetaxel tungstate Pa4586; thalidomide Pa34958; I want to separate entries into columns so that I can put into excel sheet in proper arrangement. I want entries... (4 Replies)
Discussion started by: manigrover
4 Replies

6. Shell Programming and Scripting

displaying columns based on column name

Hello, I have a huge file with many columns . I want to use the names of the columns to print columns to another file. for example file.txt COLA COLB COLC COLD 1 2 3 5 3 5 6 9 If I give name for multiple columns to the code:... (5 Replies)
Discussion started by: ryan9011
5 Replies

7. UNIX for Dummies Questions & Answers

Displaying specific columns in a file

Hi, I'm just wondering how you display a specific set of columns of a specified file in Unix. For example, if you had an AddressBook file that stores the Names, Phone numbers, and Addresses of people the user entered in the following format (the numbers are just to give an idea of what column... (1 Reply)
Discussion started by: logorob
1 Replies

8. Shell Programming and Scripting

Displaying Output in Columns

I'm writing a script to analyze the logs of an smtp relay machine and I'd like the final output to be displayed in columns showing results from the previous day, week, month, and 45 days. The problem I'm running into is that I can't figure out how to display the columns neatly so there is no... (1 Reply)
Discussion started by: jjamd64
1 Replies

9. Shell Programming and Scripting

displaying range of columns

can i display range of columns in AWk... say in cut command i can display columnm 2-13.... is there is any simmilar command in awk (1 Reply)
Discussion started by: mahabunta
1 Replies
Login or Register to Ask a Question