The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Displaying Output in Columns jjamd64 Shell Programming and Scripting 1 04-25-2008 06:46 AM
CLI Magic: A little script to customize directory listings iBot UNIX and Linux RSS News 0 12-11-2007 05:50 AM
Displaying files in a directory markjohnlowe UNIX for Dummies Questions & Answers 4 03-14-2007 08:58 AM
displaying range of columns mahabunta Shell Programming and Scripting 1 01-26-2007 05:59 AM
displaying directory in html adel66 UNIX for Dummies Questions & Answers 9 11-03-2003 09:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-03-2007
mjays mjays is offline
Registered User
  
 

Join Date: Apr 2007
Location: london
Posts: 40
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 (permalink)  
Old 04-03-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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 (permalink)  
Old 04-03-2007
mjays mjays is offline
Registered User
  
 

Join Date: Apr 2007
Location: london
Posts: 40
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 (permalink)  
Old 04-03-2007
mjays mjays is offline
Registered User
  
 

Join Date: Apr 2007
Location: london
Posts: 40
actually that hasn't quite displayed correctly. imagine all the columns are lined up.
  #5 (permalink)  
Old 04-03-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
With bash/ksh93:

Code:
set crm ifid riab
{  printf "%s\t" "$@";printf "\n";eval paste $(printf "<(ls %s) " "$@");}
  #6 (permalink)  
Old 04-03-2007
mjays mjays is offline
Registered User
  
 

Join Date: Apr 2007
Location: london
Posts: 40
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 (permalink)  
Old 04-03-2007
phystech846 phystech846 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 2
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
Closed Thread

Bookmarks

Tags
bash, bash eval, eval

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0