Skip to content

Instantly share code, notes, and snippets.

@ErykDarnowski
Last active April 11, 2024 01:03
Show Gist options
  • Save ErykDarnowski/c5555854c0d59cfd869c4118d51ae35f to your computer and use it in GitHub Desktop.
Save ErykDarnowski/c5555854c0d59cfd869c4118d51ae35f to your computer and use it in GitHub Desktop.
Print multi-line output one the same line

Print multi-line output one the same line

output

Instructions

NEW

Soo, after finding out about xargs I got this solution instead 😅:

./linePrinter.sh | xargs -l1 -d '\n' printf '\r\r%s'
OLD

Just pipe the output in to the script: ./linePrinter.sh | ./lastLineShower.sh!

*./linePrinter.sh is included for demonstration (to test out the solution)

#!/bin/bash
# Check to see if a pipe exists on stdin.
if [ -p /dev/stdin ]; then
while IFS= read line; do
printf "\r\r${line}"
done
else
echo -e "\033[0;31mNo input was piped in to the script, skipping!\033[0m"
exit 1
fi
#!/bin/bash
# Example line printer script
while true
do
echo "param: $(( $RANDOM % 50 + 1 ))"
sleep 0.1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment