LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-08-2012, 03:57 AM   #1
ModServ
LQ Newbie
 
Registered: Oct 2010
Posts: 12

Rep: Reputation: 2
Format results into table that have columns and rows


Hello,

I've a little question that makes me crazy trying to solve it.

Suppose I've a command that outputs this:
110
120
130
140
150
160

And I've a second command that outputs this:
server1
server2
server3
server4
server5
server6

And suppose also I've another commands that will output something like above.

I want to format these results into table to look like this:

Code:
ID                  Name                 HEAD1                   HEAD2
110                 server1              something1              something1
120                 server2              something2              something2
130                 server3              something3              something3
140                 server4              something4              something4
150                 server5              something5              something5
160                 server6              something6              something6
Note: All columns will have the same number of rows, In other words if ID 110 exists then all its row must exist, etc...

I hope I find the solution here.

Thank You!

Last edited by ModServ; 01-08-2012 at 03:58 AM.
 
Old 01-08-2012, 08:42 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,934
Blog Entries: 45

Rep: Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169
Moderator response

Hi,

What have you done to find a solution to the problem? Other than to post here.

We will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist. 


 
Old 01-08-2012, 10:51 PM   #3
ModServ
LQ Newbie
 
Registered: Oct 2010
Posts: 12

Original Poster
Rep: Reputation: 2
Hello,

Posting here was the latest solution, I've tried near everything, printf, awk, sed, for loop, while.

Can't format it into table.
 
Old 01-09-2012, 12:01 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,378

Rep: Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755
As hinted by onebuck, show us your best attempt and we'll help(!) you fix it
 
Old 01-09-2012, 06:32 AM   #5
ModServ
LQ Newbie
 
Registered: Oct 2010
Posts: 12

Original Poster
Rep: Reputation: 2
Hello,

I guess that we come here andopen a request to get a help or an answer and not get all these posts because we want to know something!

Will that kill all of you to post the answer ? Does that will be so hard!

If you don't want to answer, Then thanks for your replies.

Anyway, I've used this "column -x", used the columnize script, and other ways "THAT I DO NOT REMEMBER".

But really, I'm surprised with these posts because I've post a topic that was my first topic ever and I guess it will be the last one.

Thank you !!
 
Old 01-09-2012, 07:32 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,756
Blog Entries: 4

Rep: Reputation: 3966Reputation: 3966Reputation: 3966Reputation: 3966Reputation: 3966Reputation: 3966Reputation: 3966Reputation: 3966Reputation: 3966Reputation: 3966Reputation: 3966
Write it out as HTML and invoke a web-browser to display it.
 
1 members found this post helpful.
Old 01-09-2012, 08:42 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,934
Blog Entries: 45

Rep: Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169Reputation: 3169
Moderator response

Hi,
Quote:
Originally Posted by ModServ View Post
Hello,
I guess that we come here andopen a request to get a help or an answer and not get all these posts because we want to know something!

Will that kill all of you to post the answer ? Does that will be so hard!

If you don't want to answer, Then thanks for your replies.

Anyway, I've used this "column -x", used the columnize script, and other ways "THAT I DO NOT REMEMBER".

But really, I'm surprised with these posts because I've post a topic that was my first topic ever and I guess it will be the last one.

Thank you !!
Just post the material that you have done so we can aid you with the problems you are having. Please place the cod within the vbcode tag #. You will find that at the top of the reply window as a '#' sign. This will encase the code and make it cleaner therefore easier to read & diagnose.

We are here to help and not do the work for you.

Just a few links to aid you to gaining some understanding. I would start at 4,5 &6 while the other links will enhance your experience;



1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Utimate Linux Newbie Guide

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!


FYI: I suggest that you look at 'How to Ask Questions the Smart Way' so in the future your queries provide information that will aid us in diagnosis of the problem or query.


 
Old 01-09-2012, 09:38 AM   #8
ModServ
LQ Newbie
 
Registered: Oct 2010
Posts: 12

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by sundialsvcs View Post
Write it out as HTML and invoke a web-browser to display it.
Thank you for your reply, Unfortunately that code will be used in SSH only, As it will output results of VPSes on the node.

Quote:
Just post the material that you have done so we can aid you with the problems you are having. Please place the cod within the vbcode tag #. You will find that at the top of the reply window as a '#' sign. This will encase the code and make it cleaner therefore easier to read & diagnose.
I've post what I've been used, But as you know when you do something and fail you remove it, So, I don't have the exact commands that I've used.

Quote:
We are here to help and not do the work for you.
I'm not looking for someone to work for me, If I was, I would pay $$$ for anyone, But that's not my target.

Quote:
Just a few links to aid you to gaining some understanding. I would start at 4,5 &6 while the other links will enhance your experience;



1 Linux Documentation Project

2 Rute Tutorial & Exposition

3 Linux Command Guide 

4 Bash Beginners Guide

5 Bash Reference Manual

6 Advanced Bash-Scripting Guide

7 Linux Newbie Admin Guide

8 LinuxSelfHelp

9 Utimate Linux Newbie Guide
Thanks for these URLs, I've made a lot of bash scripts to manage, secure, improve, and monitor servers, So, I'm not a newbie, I just faced something that can't be done in anyway, BTW, That's the first time I decide to open a topic to request for help as I always depend on myself, But as I know "or may I expect" that people help others.

If I post what I've tried -That I don't remember- Will that help ?

Anyway, Thanks for all who replied to me.

Moderator, Please close this thread as it seems that nobody will help me unless I put what I've tried -That I don't remember-.

Best wishes,
 
Old 01-09-2012, 09:51 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by ModServ View Post
Anyway, I've used this "column -x", used the columnize script
If the output of the commands you mentioned in your first post is already in column, you don't need the column command. Instead try paste in conjunction with process substitution. paste usually serves to join files side-by-side, but process substitution mimics files in the sense it opens a file descriptor and send output there (from where other commands can receive their input as if it's read from a file). Example:
Code:
paste <(command_one) <(command_two) <(command three)
Hope this helps.
 
Old 01-16-2012, 04:35 PM   #10
ModServ
LQ Newbie
 
Registered: Oct 2010
Posts: 12

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by colucix View Post
If the output of the commands you mentioned in your first post is already in column, you don't need the column command. Instead try paste in conjunction with process substitution. paste usually serves to join files side-by-side, but process substitution mimics files in the sense it opens a file descriptor and send output there (from where other commands can receive their input as if it's read from a file). Example:
Code:
paste <(command_one) <(command_two) <(command three)
Hope this helps.
Thank you for your response and help, I've tried those with 2 commands and that was the result:

Code:
root@xxxxxx [~]# paste 1.txt 2.txt
110 120 130 140 150 160 170     server1 server2 server3 server4 server5 server6 server7
That's so weird as the result must be columnized, Do you have any suggestions or explanation for this behaviour ?

Best wishes,
 
Old 01-16-2012, 06:59 PM   #11
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi ModServ,

You didn't even pose the problem correctly.

In the examples, the data in each file is shown with line breaks after each word - thus:
Quote:
Suppose I've a command that outputs this:
110
120
130
140
150
160

And I've a second command that outputs this:
server1
server2
.
but when someone gives the solution, you show the format without line breaks - thus.
1.txt
Quote:
110 120 130 140 150 160 170
and
2.txt
Quote:
110 120 130 140 150 160 170
So now YOU PLEASE TRY TO CONVERT THE FILE TO HAVE A LINE BREAK AFTER EVERY WORD.

OK
 
Old 01-18-2012, 06:41 AM   #12
ModServ
LQ Newbie
 
Registered: Oct 2010
Posts: 12

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by AnanthaP View Post
Hi ModServ,

You didn't even pose the problem correctly.

In the examples, the data in each file is shown with line breaks after each word - thus:


but when someone gives the solution, you show the format without line breaks - thus.
1.txt
and
2.txt


So now YOU PLEASE TRY TO CONVERT THE FILE TO HAVE A LINE BREAK AFTER EVERY WORD.

OK
Hello,

You are right, That's my fault, I assumed that the result is formatted inside the text have line breaks, Anyway I've fixed this:

root@server [~]# paste 1.txt 2.txt
Code:
110     server1
120     server2
130     server3
140     server4
150     server5
160     server6
170     server7
Thanks to anyone helped me, Have you all a nice day.

Best regards,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Output data to an ascii table genderbender Programming 1 10-18-2010 08:55 AM
[SOLVED] SQL Command output to bash variables chirayu11 Linux - Newbie 5 08-04-2010 07:40 AM
ambiguous output using variables in bash gwong Linux - Newbie 2 05-05-2007 08:49 PM
read values of variables from a table osio Programming 7 01-11-2006 02:52 AM
i need rpm output in table format Uday123 Fedora 1 12-17-2005 05:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration