Output of shell in array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output of shell in array
# 1  
Old 05-26-2011
Output of shell in array

Hi,

i have a file which reads,

Code:
arun/manager/200000
pradeep/engineer/10000
karthik/teamlead/30000

.....

i want an output to show,

Code:
name        role         salary
=======================
arun         manager    200000
pradeep    engineer    10000

and so on..

i want to do this with arraysSmilie,
kindly help.

thanks,
Pradeep.

Last edited by joeyg; 05-26-2011 at 03:16 PM.. Reason: please use codetags for scripts and data
# 2  
Old 05-26-2011
Well, boilerplate header from 'echo' and 'tr' the '/' to a tab is a start.

Want justification? I wrote a C fixed pitch formatter, autotab.c, or you can go to Excel or HTML!
# 3  
Old 05-26-2011
KSH, at least, does not have mutli-dimensional arrays built in.

You can write you're own code to implement them....for example, these are functions I wrote:
Code:
###################################################################################
# Main line here
###################################################################################
init_array

create_array LIST[3,3,1]

set_array_index_name LIST[2]="Name,Role,Salary"

set_array LIST[1,,]="arun,manager,200000"
set_array LIST[2,,]="pradeep,engineer,10000"
set_array LIST[3,,]="karthik,teamlead,30000"

print_array LIST

get_array LIST[1,1,1]

Ouput:
Code:
Z=1     Name    Role     Salary
       ┌───────┬────────┬──────┐
      1│   arun│ manager│200000│
       ├───────┼────────┼──────┤
      2│pradeep│engineer│ 10000│
       ├───────┼────────┼──────┤
      3│karthik│teamlead│ 30000│
       └───────┴────────┴──────┘

arun

# 4  
Old 05-26-2011
Sounds cool, purdym. But it does no one any good unless you post the code for the functions you wrote.
# 5  
Old 05-26-2011
I've thought about releasing the code, I spent a lot of time developing it. I can't guarantee its bug free. Perhaps someone has time see if it works on their system.
# 6  
Old 05-26-2011
maybe try something this
Code:
# cat file
arun/manager/200000
pradeep/engineer/10000
karthik/teamlead/30000

Code:
# ./justdoit file
    name        role       salary
  =================================
    arun      manager       200000
 pradeep     engineer        10000
 karthik     teamlead        30000

Code:
#!/bin/bash
F="==========="
echo -e "    name\trole\t   salary\n  $F$F$F"
while read -r l ; do
array=($(echo $l|sed 's/[/]/ /g' )) ;c=${#array[@]}
for((i=0;i<$c;i++)) ; do arrpr=(${arrpr[@]} ${array[i]} )
done;array=();printf "%8s %12s %12s\n" ${arrpr[@]};arrpr=();done<$1

regards
ygemici
# 7  
Old 05-27-2011
thanks a lot Smilie, it works perfect,
but, can u just go thru the code, and explain a bit ?

regards,
Pradeep
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies

2. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

3. UNIX for Dummies Questions & Answers

Formatting Array Output

Hello All, Q1) I have the below code but when the email was sent out all lines are merged and coming out as a single line though my printf statement has newline "\n", How do i avoid that? Q2) In my second IF statement when i introduced the backslash "\" for continuation of a line or command, i... (10 Replies)
Discussion started by: Ariean
10 Replies

4. Shell Programming and Scripting

Output find to array

Hi I'm trying to write a shell script which finds all the .zip files in a given directory then lists them on the screen and prompts the user to select one by entering a number e.g. The available files are: 1. HaveANiceDay.zip 2. LinuxHelp.zip 3. Arrays.zip Please enter the... (4 Replies)
Discussion started by: zX TheRipper Xz
4 Replies

5. Shell Programming and Scripting

Store the output values in array

Hi, How to store the values in array from output result, EG: I have the result like this, ps, google, 1.txt, 1 sam, google, 2.txt, 2 These are the four values followed by comma in two sets. I need to store these values set by set. One set contains four values followed by comma. ... (2 Replies)
Discussion started by: KarthikPS
2 Replies

6. Shell Programming and Scripting

Output file list to array?

Hey, guys, scripting newb here. I'm trying to get a list of all .dmg files in a folder and save the output into an array. My first attempt was ARRAY= ( `ls $REIMAGEPATH | grep \.dmg$` ) However, I understand why that doesn't work now (at least I think I do). But I don't know what the... (5 Replies)
Discussion started by: nextyoyoma
5 Replies

7. Shell Programming and Scripting

Sorting awk array output?

Hi all, I have a script which produces a nice table but I want to sort it on column 3. This is the output line in the script: # Output { FS = ":"; format = "%11s %6s %-16s\n"; prinft "\n" printf ( format, "Size","Count","Who" ) } for (i in... (21 Replies)
Discussion started by: Cowardly
21 Replies

8. Filesystems, Disks and Memory

iostat output vs TPC output (array layer)

Hi Guys, I've been having some arguments with my colleagues about one thing. Always my thought was that as as far as disk performance is concern by looking at the output of the iostat command (AIX) you would be able to identify if you have a hot disk and then by moving some files out that disk... (3 Replies)
Discussion started by: arizah
3 Replies

9. Shell Programming and Scripting

Put output into an array

I'm trying to take the output of an environment that has multiple strings ex. # echo $SSH_CLIENT 192.168.1.1 57039 22 I need that IP... so I can set it to another environment. Thank you (3 Replies)
Discussion started by: adelsin
3 Replies

10. Shell Programming and Scripting

output of an array

Hi gurus, I need to set up an array like this set - A arr 'A', 'B' The output of this array should be like this 'A','B' Right now, I get the output like this 'A B' Can anyone suggest me on how to achieve this. thanks (3 Replies)
Discussion started by: ragha81
3 Replies
Login or Register to Ask a Question