Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output multiple commands into columns

Tags:

bash

I'm trying to write a script which runs various commands and outputs the result of each command into one column but I'm not able to get the output ot be displayed in colums.

#!/bin/bash

# Get GBP Neighbour NAMES
NEIGHBOR=$(vtysh -c 'show ip bgp neighbors' | grep Incoming | awk '{print $7}')

# Get IPs of BGP neighbours
IP=$(vtysh -c 'show ip bgp summary' | awk '{print $1}' | head -n -2 | tail -n +6)

# Get Up/Down time
TIME=$(vtysh -c 'show ip bgp summary' | awk '{print $9}' | head -n -2 | tail -n +6)

# Get State/PfxRcd
STATE=$(vtysh -c 'show ip bgp summary' | awk '{print $10}' | head -n -2 | tail -n +6)

How can I get the output to be separated in columns such as:

NEIGHBOR | IP | TIME | STATE
like image 434
Kevin Maschke Avatar asked Nov 14 '17 11:11

Kevin Maschke


1 Answers

With paste command:

paste -d'|' <(echo "$NEIGHBOR ") <(echo "$IP") <(echo "$TIME") <(echo "$STATE")
like image 79
RomanPerekhrest Avatar answered Oct 24 '22 14:10

RomanPerekhrest