Search and Replace Product by Name UNIX

 #!/bin/bash


# Function to search and replace product name

search_and_replace() {

    local search=$1

    local replace=$2


    if grep -q "$search" products.txt; then

        sed -i "s/$search/$replace/" products.txt

        echo "Product '$search' has been replaced with '$replace'."

    else

        echo "Product '$search' not found in the product list."

    fi

}


# Example usage: search and replace 'Orange' with 'Kiwi'

search_and_replace "Orange" "Kiwi"

Comments