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.
# 8  
Old 04-03-2007
"${@##*/}": bad substitution
# 9  
Old 04-03-2007
Quote:
Originally Posted by mjays
"${@##*/}": bad substitution
I said bash/ksh93!
# 10  
Old 04-03-2007
Something like the following should get you started:

Code:
$ touch dir_1/file_{1,2,3,4,5}
$ touch dir_2/newfile_{a,b,c,d,e,f,g}
$ touch dir_3/another_file_{one,two,three,four}
$ cat 3cols.sh
#!/bin/bash

DIR1="dir_1"
DIR2="dir_2"
DIR3="dir_3"

paste -d';' <( ls ${DIR1} ) <( ls ${DIR2} ) <( ls ${DIR3} ) | while read LINE; do
   FILE1=$( echo "${LINE}" | cut -d';' -f1 )
   FILE2=$( echo "${LINE}" | cut -d';' -f2 )
   FILE3=$( echo "${LINE}" | cut -d';' -f3 )
   printf "%-20s\t%-20s\t%-20s\n" "${FILE1:- }" "${FILE2:- }" "${FILE3:- }"
done

exit 0
$ chmod +x ./3cols.sh 
$ ./3cols.sh 
file_1                  newfile_a               another_file_four   
file_2                  newfile_b               another_file_one    
file_3                  newfile_c               another_file_three  
file_4                  newfile_d               another_file_two    
file_5                  newfile_e                                   
                        newfile_f                                   
                        newfile_g

Cheers
ZB
# 11  
Old 04-03-2007
Let me try - this is my first script - so please be lenient!

I used tmp-files and I think it's not good, probably rs can do the trick. But this script is working. It takes names of directories as arguments (there may be more than 3 arguments) and prints the names of files conlumnwise.

#!/bin/sh

for i in $*
do
echo $i > my_temp_file_$i
ls $i >> my_temp_file_$i
echo my_temp_file_$i >> list_of_temp_files
done

pr -m -l 2 `cat list_of_temp_files`

for i in $*
do
rm my_temp_file_$i
done

rm list_of_temp_files
# 12  
Old 04-03-2007
With bash/ksh93:

Code:
set /mg_apps/crm /mg_apps/ifid /mg_apps/riab 
{  printf "%-24s" "${@##*/}";printf "\n";eval pr -ml2 $(printf "<(ls %s) " "$@");}

# 13  
Old 04-03-2007
radoulov - thank you, but up until you added the substition "${@##*/}"; your command worked. we only have 'ksh' here and not 'bash/ksh93'.


phystech846 - thank you, but your attempt uses temp files and i was trying to avoid creating files - i find it a bit messy. nice effort though.


Zazzybob - perfect, works a treat - everything lines up nice and straight. thank you. i'm using your attempt, with an extra 'prinf' line for the column titles. see below.


$ cat sol3.ksh
#!/bin/ksh
DIR1="/mg_apps/crm"
DIR2="/mg_apps/ifid"
DIR3="/mg_apps/riab"

printf "%-20s\t%-20s\t%-20s\n" "crm" "ifid" "riab"
echo ""
paste -d';' <( ls ${DIR1} ) <( ls ${DIR2} ) <( ls ${DIR3} ) | while read LINE; do
FILE1=$( echo "${LINE}" | cut -d';' -f1 )
FILE2=$( echo "${LINE}" | cut -d';' -f2 )
FILE3=$( echo "${LINE}" | cut -d';' -f3 )
printf "%-20s\t%-20s\t%-20s\n" "${FILE1:- }" "${FILE2:- }" "${FILE3:- }"
done
# 14  
Old 04-03-2007
Quote:
Originally Posted by mjays
radoulov - thank you, but up until you added the substition "${@##*/}"; your command worked. we only have 'ksh' here and not 'bash/ksh93'.
[...]
I'm not sure this works with ksh93 though Smilie
You seem to have ksh93 (process substitution is not available in ksh88).

Last edited by radoulov; 04-03-2007 at 10:37 AM..
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