From 2990f89058c0869e533c67f2a3e7c17a4deb2164 Mon Sep 17 00:00:00 2001 From: Riccardo Carlesso Date: Mon, 22 Jul 2024 11:42:24 +0200 Subject: [PATCH] Add colorizing functionality to specified column --- bin/colorize_column | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 bin/colorize_column diff --git a/bin/colorize_column b/bin/colorize_column new file mode 100755 index 0000000..422d6d1 --- /dev/null +++ b/bin/colorize_column @@ -0,0 +1,37 @@ +#!/bin/bash + +# echo this was written with Gemini +# BUG: This doesnt preserve spaces.. but its good enough for today. + +# Check if the column number is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +column_number="$1" + +# Read input line by line +while IFS= read -r line; do +#while read -r line; do + # Split the line into words + words=($line) + + # Check if the column number is valid + if [ "$column_number" -gt "${#words[@]}" ] || [ "$column_number" -lt 1 ]; then + echo "Invalid column number: $column_number" + continue + fi + + # Colorize the specified column +# printf "AA%s " "${words[@]:0:$column_number - 1}" # Print words before the column +# printf "BB\033[1;31m%s\033[0m " "${words[$column_number - 1]}" # Print and colorize the column +# printf "CC%s\n" "${words[@]:$column_number}" # Print words after the column + + echo -n "${words[@]:0:$column_number - 1}" # Print words before the column + echo -en " \033[1;33m${words[$column_number - 1]}\033[0m " # Print and colorize the column + echo "${words[@]:$column_number}" # Print words after the column + + +done +