Search This Blog

Sunday, October 1, 2023

Shell script 13

Question:

Write a script to replace a pattern with other pattern without opening the file.

Answer:

#!/usr/bin/bash

inputfile="/home/kalam/filename.sh"

if [ -e $inputfile ]

then

        echo "File is exists in the following path: $inputfile"

        #pattern to replaced

        pattern_to_replace="state_name"

        #replacement pattern

        replacement_text="STATE_NAME"

        sed -i "s/$pattern_to_replace/$replacement_text/g" "$input file"

        echo "pattern '$pattern_to_replace' replaced with '$replacement_text' in '$inputfile'"

else

        echo "file not found: $inputfile"

        echo "Please provide realpath of the file and re-run the script\n Thank you for using this script"

fi

output:

echo "Please Provide the user name and state name"

read name STATE_NAME

echo "User provided name is :$name and His state name is : $STATE_NAME "

if [ "$STATE_NAME" =  "andra" ]; then

        echo "$name speaks Telugu"

else

        echo "$name does not speak Telugu"

fi





No comments:

Post a Comment

What is the sanity checks you have done for STA?

 Sanity checks for STA: Linking Checks: We need to check., is there any missing modules or missing pins in a library. this is done by link c...