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.
# 1  
Old 04-03-2007
displaying 3 directory listings in 3 separate columns.

i having problems figuring out how to 'read' in 3 different directory listings and then display them on the screen into 3 separate columns.

i thought i could use a 'for' loop to grab each directory and then assign a unique variable to each line 'read' in.

of course, as you experts all know, you can't do env$num=$env.

an example of the script i had in mind is below.


#!/bin/ksh
num=0
for env in `ls /mg_apps/crm` `ls /mg_apps/ifid` `ls /mg_apps/riab`
do
env$num=$env
num=`expr $num + 1`
done

echo "crm" "ifid" "riab"
echo $env1 $env4 $env7
echo $env2 $env5 $env8
echo $env3 $env6 $env9



however, this method, even if it did work, also has it's own problems - what happens when a new directory is created? it would throw the variable numbering out and i'd get a 'crm' directory appearing in the 'ifid' column.

all solutions greatly appreciated, i love to see diversity, it increases my knowledge of unix.

cheers.
# 2  
Old 04-03-2007
Code:
ls /mg_apps/crm > /crm_fl
ls /mg_apps/ifid > /fd_fl
ls /mg_apps/riab > /iab_fl
paste /crm_fl /fd_fl /iab_fl

# 3  
Old 04-03-2007
thanks for that. it works, but i didn't want to mess about with creating files and then deleting them.

i also then have to figure out how to get a title at the top of each column and then display in lovely straight lines.

e.g.

crm ifid

crmuat1 ifiduat
crmproduction ifiduat2
crmuat2 ifiddev
# 4  
Old 04-03-2007
actually that hasn't quite displayed correctly. imagine all the columns are lined up.
# 5  
Old 04-03-2007
With bash/ksh93:

Code:
set crm ifid riab
{  printf "%s\t" "$@";printf "\n";eval paste $(printf "<(ls %s) " "$@");}

# 6  
Old 04-03-2007
thank you radoulov, but still not quite what i was after.

once i've placed the full path name of crm, ifid or riab in the 'set' command, i get the full path name as a heading, which is a little messy.

it's also still not aligned in nice straight columns. see the output below.

e.g.

/mg_apps/crm /mg_apps/ifid /mg_apps/riab
crm_MKS_build ifiddev dev
crmdev ifidprd prod
crmprd ifiduat uat
crmuat
reladmin
# 7  
Old 04-03-2007
Quote:
Originally Posted by mjays
thank you radoulov, but still not quite what i was after.

once i've placed the full path name of crm, ifid or riab in the 'set' command, i get the full path name as a heading, which is a little messy.
[...]
Code:
{  printf "%s\t" "${@##*/}";printf "\n";eval paste $(printf "<(ls %s) " "$@");}

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