himquantum / python-data-project

data analysis using python
0 stars 0 forks source link

Awk new string vv #1

Open himquantum opened 5 months ago

himquantum commented 5 months ago

!/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"