Display echo results in three column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display echo results in three column
# 1  
Old 02-15-2010
Display echo results in three column

Dear Friends,

I have my command output which displays on one row and values are now scrollable (vertical) 3 pages. How do i display those output in three column so that i no need to scroll?

Example:
dcadd$cat components

1.Caluculator
2.Diary
...
...
50.Mobile
51.Battery
..
...
....
100.Signal
101.Headphone


Want to display as follows

1. Caluculator 50.Mobile 100.Signal
2. Diary 51.Battery 101.Headphone
... .... ....
... .... ....
49.Message 99.MMS 149.Games

Basically converting row ouotput in to column output which produced by echo command.

Thanks
Bala
# 2  
Old 02-15-2010
don't you have the 'column' utility ?
try 'man column'
# 3  
Old 02-15-2010
Sorry. i don't have.

Is there anything to do with echo?
# 4  
Old 02-15-2010
There's something wrong with the logic.

You're combining the lines 1,50 and 100, 2,51 and 101 and so forth.

The output contains 49 lines and the last line is a combination of line 49, 98 and 148.

That means that line 99 is missing in the output, check the scheme below:

Quote:
1,50,100
2,51,101
.
.
48,97,147
49,98,148
# 5  
Old 02-15-2010
Something like this (not sure for the indexing)
Code:
# create an aray with the data
while read L
do   
    T[$i]="$L"
    ((i++))
done < components
# display the array
COLS=3
ROWS=$((${#T[@]}/$COLS))
for ((i=0; i<$ROWS; i++))
do
    for ((j=0; i=<$COLS; j++))
    do
        echo -e "\t$i : t${T[$((i+ROWS*j))]}
    done
    echo
done

I'm sure awk could do the job fine...
# 6  
Old 02-16-2010
Dear friends,,

Basically my output will be 1 to 150 lines. at a time i can see 50 lines then i should scroll another page to view 51-100 etc.

This i want to view in one page which is

1-50 first column
51-100 second column
100-150 third colum.

It is not necessary to split exactly as about. For the given output need to devide in to three column.

Thanks
Bala
# 7  
Old 02-16-2010
Assuming you want to combine line 1 with 51 and 101, line 2 with 52 and 102 and so forth:

Code:
awk '{a[NR%50]=a[NR%50]?a[NR%50] FS $0: $0}
END{for(i=1;i<50;i++){print a[i]};print a[0]}
' components

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to display some special results with AWK

I have a file like this: AAEQGAGNQPQH,,,,160,32,,,, AAGQDYNSPLH,,712,39,,,,,, AAGREGGNTEAF,26,,,,,,,,4 AAGSPQH,,,,8,5,,,, AAKKLGQFYNEQF,4,,6,,,7,,,2 AANSGGRYNEQF,,2747,3120,,,,,, AAQGGVGGELF,,,,5,,12,36,, AAQGLAGYYEQY,,25,13,,,,,, AAQRGNEQF,510,2,,,6,,6,,76 AAQTGENSPLH,,16,16,,,,,, The... (9 Replies)
Discussion started by: xshang
9 Replies

2. Shell Programming and Scripting

display echo only once

lets say I am printing something out echo "Please enter a valid username" and its being printed out 5 times, is there any way I can limit to only being displayed ONCE. I tried echo -n but that just makes everything fit on one line. Right now it keeps saying Please enter a valid... (5 Replies)
Discussion started by: subway69
5 Replies

3. UNIX and Linux Applications

Display mysql results nicely

Hi, perhaps this is a dumb question. I'm running queries on mysql and I'm getting tabbed results like these: mysql> SELECT * from metrics_status WHERE date = '2012-03-30'; <TABLE... (1 Reply)
Discussion started by: erick_tuk
1 Replies

4. Homework & Coursework Questions

Using ls or echo to display a specific output

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: What single command line would you enter to get the following output? 8140 drwxr-xr-x 9 root bin 18 Jan 20... (6 Replies)
Discussion started by: dasboot
6 Replies

5. Shell Programming and Scripting

Display find results, and pipe to xargs

I have an overnight script which runs across a large directory to repair permissions and ownership. I also have this command output the list of files affected so that cron can email these as a log file. Previously I had the command in the form: find /path/to/files -not -user myname -print -exec... (4 Replies)
Discussion started by: mij
4 Replies

6. Shell Programming and Scripting

echo display problem

Hi I am facing a strange problem a=03 echo ${a} the output is 3 But i want to display it is 03 Can you people help me how to display it like 03. Thanks (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

7. UNIX for Dummies Questions & Answers

How to display first 7 char of grep results?

My file contains the following: uat2000.aspclient.active=true uat2001.aspclient.active=true uat2002.aspclient.active=true uat2003.aspclient.active=true uat2004.aspclient.active=false uat2005.aspclient.active=false uat2006.aspclient.active=false uat2007.aspclient.active=false... (8 Replies)
Discussion started by: kthatch
8 Replies

8. Shell Programming and Scripting

what does echo $$ command display

whats the value stored in $$ (2 Replies)
Discussion started by: suri
2 Replies

9. Solaris

Top and Prstat display different results for memory

I have a question about the accuracy of prstat. I did a 'prstat -t' and it shows 99% of my memory is occupied by oracle. NPROC USERNAME SIZE RSS MEMORY TIME CPU 194 oracle 343G 340G 99% 86:17.24 56% However, 'top' shows I still have 7762meg of memory free. Memory: 16G real, 7762M... (4 Replies)
Discussion started by: zen03
4 Replies

10. UNIX for Dummies Questions & Answers

Display from a variable using echo.

I have a variable that is outputting a lot of space. here has been 45 lines returned ... how can I remove the spaces between the "been and the 45" CODE: fil_len=`wc -l < coshb.txt` if ; then cat coshb.txt | more echo " " echo "There has been ${fil_len} lines... (4 Replies)
Discussion started by: jagannatha
4 Replies
Login or Register to Ask a Question