Last active
December 31, 2021 09:01
-
-
Save Rendevior/d08410df173ed2b48d36ff87e212a787 to your computer and use it in GitHub Desktop.
Easiest way to Center Multiline Text in Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function Centered(){ | |
echo "$1" | sed -e :a -e "s/^.\{1,$(tput cols)\}$/ & /;ta" | tr '\n' '\r' | |
} | |
# Using Pipe | |
function CenteredPipe(){ | |
sed -e :a -e "s/^.\{1,$(tput cols)\}$/ & /;ta" /dev/stdin | tr '\n' '\r' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
~# Centered "Hello World Center"
~# echo "Hello World Center" | CenteredPipe