Open himquantum opened 5 months ago
read -p "Enter the file path: " input_file
if [ ! -f "$input_file" ]; then echo "File not found!" exit 1 fi
read -p "Enter the new string: " new_string
awk -v new_string="$new_string" '!/^$/{gsub(substr($0, 3, 22), new_string)}1' "$input_file"
!/bin/bash
Ask the user to input the file path
read -p "Enter the file path: " input_file
Check if the file exists
if [ ! -f "$input_file" ]; then echo "File not found!" exit 1 fi
Ask the user to input the new string
read -p "Enter the new string: " new_string
Use awk with gsub to replace characters from position 3 to 24 with the new string for non-blank lines
awk -v new_string="$new_string" '!/^$/{gsub(substr($0, 3, 22), new_string)}1' "$input_file"