Arranging the output of a shell script into tables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Arranging the output of a shell script into tables
# 1  
Old 05-17-2016
Arranging the output of a shell script into tables

Hi guys.
I am new to this forum so cheers Smilie

I have a question.
I have created a shell script that puts all the output into 1 file.
The out put is like this:
-----IP------
Data
Data
Data
-----IP------
Data
Data
Data

How can i arrange this to be like this:
Code:
   IP       | Data      | Data    | Data
192.168.1.1 | Data 123 | Data 123 | Data 123
192.168.1.1 | Data 123 | Data 123 | Data 123

My script is really simple:
Code:
for server in $(cat server.txt)
do 
	echo -------$server------- >> output file
	ssh root@$server 'asterisk -rx "core show channels" | grep "active";asterisk -rx "sip show channels" | grep "active"' >> output file
done



Thank you friends

Last edited by vbe; 05-17-2016 at 02:46 PM..
# 2  
Old 05-17-2016
You can use printf and xargs
Code:
for server in $(cat server.txt)
do 
    printf "%s" "$server"
    ssh root@"$server" 'asterisk -rx "core show channels" | grep "active";asterisk -rx "sip show channels" | grep "active"' |
      xargs printf " | %s"
    printf "\n"
done > outputfile

# 3  
Old 05-17-2016
Thank you
It does put it in a sort of table
Here is the new output
Code:
IP | 45 | active | channels | 23 | active | calls | 27 | active | SIP | dialogs

So now i will try to figure out how to fix the output to look cleaner

Thanks again

---------- Post updated at 05:34 PM ---------- Previous update was at 03:07 PM ----------

I am trying to fix this to be like this
Code:
      IP         |        Channels       |     Calls           |
192.168.1.1  |  5 active channels  |  3 active calls  |

But i cannot find any where how i implement the column extension or how to sort this out since the current output is
Code:
IP | 45 | active | channels | 23 | active | calls | 27 | active | SIP | dialogs

Thanks for the help guys
# 4  
Old 05-18-2016
We have a rough idea how your current output file looks like.
How about a more exact example?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script automation using cron which query's MySQL Tables

What I have: I have a input.sh (script which basically connect to mysql-db and query's multiple tables to write back the output to output1.out file in a directory) note: I need to pass an integer (unique_id = anything b/w 1- 1000) next to the script everytime I run the script which generates... (3 Replies)
Discussion started by: kkpand
3 Replies

2. Shell Programming and Scripting

Arranging the command output into an html table format

Hi, I need to format a command output for the beolow command: runmqckm -cert -list -db $MQ_KDB -pw $PASSWD -expiry $EXP | grep -v "Certificates in database" The output will be: "ABC - cert name" From: Tuesday, May 25, 1999 11:09:40 AM CDT To: Saturday, May 25, 2019 11:39:40 AM CDT ... (3 Replies)
Discussion started by: bdpl
3 Replies

3. Shell Programming and Scripting

Arranging output for 2 commands

I am trying to run 2 sets of commands but want their output in a particular format. The 2 commands are : md5sum $WAR_DIR/$war and java -jar $WAR_DIR/$war | grep build.release.version | awk '{print $3}' The first command gives an output of 5f5261a33b92a36f80218cf14e8271ad ... (4 Replies)
Discussion started by: Junaid Subhani
4 Replies

4. Shell Programming and Scripting

How to use V$tables in UNIX shell script?

Hi All, In my script I have used the below code to retrieve the instance name V_INSTANCE_NAME=`sqlplus -s ${APPS_USR_PSWD} <<+ set pagesize 0 linesize 256 feedback off verify off head off echo off set serveroutput off select... (2 Replies)
Discussion started by: kalidoss
2 Replies

5. Shell Programming and Scripting

Arranging Haphazard output in readable format

Dear Friends, Need your help once again. I have a sql to download output in pipe separated format. Due to that output looks haphazard. E.G. $cat output.temp 123|456|789|0 67345123||3455|1 7124563|432343414||345324 By any was can we arrange it in tabular format for better... (4 Replies)
Discussion started by: anushree.a
4 Replies

6. Shell Programming and Scripting

Need Help in arranging the output

Hello All, Please find attached input and output files. I want to write a shell script to achieve this. I tried using awk but not getting how to do this as I am new to shell programming. Thanks (4 Replies)
Discussion started by: Sudeep Bhattad
4 Replies

7. Shell Programming and Scripting

Need help in updating the tables inside shell script

I have an input file with contents like : 1LMXTJJD0W28TX2 1LS1XJGDEVWAC5T 1LK81JVDE2HRNDG 1LMXTJJD0W28TX2 1LS1XJGDEVWAC5T 1LK81JVDE2HRNDG 1LMXTJJD0W28TX2 I need to read each field from the file pass it to a query: select count(*) from usage_error where usage_id='$field... (17 Replies)
Discussion started by: Rajesh Putnala
17 Replies

8. Shell Programming and Scripting

Shell script for comparing data of tables

Hi, I have two databases with same tables on different servers.I need to check the data content in each table and if something is missing, should print that. I have a tool which takes the snapshot the table structure,index so on and compares with the other server tables snapshot. Now i need... (1 Reply)
Discussion started by: nessj
1 Replies

9. Shell Programming and Scripting

Tables to query to find users for database from shell script

I am coding shell script. I need to connect to different databases like DB2, Oracle and Sybase. I would then need to query tables where it has all the groups, users for that database. I would also need who has what kind of permissions. EG: I know for DB2 some TABAUTH table needs to be... (0 Replies)
Discussion started by: pinnacle
0 Replies

10. Shell Programming and Scripting

compare two tables using shell script

Hi, I want to compare two tables fieldwise using shell script. Can anyone help me regarding the same. The approach which i tried is to first move the two tables in simple txt file where each field is now seperated by space. But i can't retrive each field with "space" as a seperator b'coz there... (1 Reply)
Discussion started by: dtidke
1 Replies
Login or Register to Ask a Question