8

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

1 Answer 1

14

With paste command:

paste -d'|' <(echo "$NEIGHBOR ") <(echo "$IP") <(echo "$TIME") <(echo "$STATE")
Sign up to request clarification or add additional context in comments.

3 Comments

Wow! Great! Anyway to make the columns have the same width? to make it look cleaner and easier to read?
@KevinMaschke, try to pipe to column command, paste ... | column -s'|' -t
Thanks @RomanPerekhrest ! Adding | column -s '|' -t did the trick! I edited the question with the final result!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.