Reputation: 131
Suppose we do have a previously created file ABC
cat ABC //Checking contents of **ABC**
hello
hi
how
what
where
Now with the help of shell script i do want to remove the word 'how' from ABC
I am trying this
echo Enter file name
read a
if[ $a -f ]
then
_____ |grep how ABC
fi
Is there any command which can be used at _____?
All other solution are also welcome.
Upvotes: 2
Views: 55
Reputation: 785136
You can use sed
:
read -p "Enter file name: " file
[[ -f "$file" ]] && sed -i.bak '/how/d' ABC
/how/d
will delete line with the pattern how
in file ABC
if found and save the changes back into ABC
. It also creates a backup of original file with the name ABC.bak
in case something goes wrong.
In case you want to replace only a single word (without deleting whole line containing that word) then use:
sed -i.bak 's/how//' ABC
Upvotes: 3