I am completely new to sed script. I have been researching how to add text to a file and managed to get the text I want adding to the correct line in the file but can not find a way to add it to the correct position! so the line I have in the text file looks like this
/^From: \s*(.*@)?(((test\.new\.com)))/ REJECT You are not me
and i want to get input from user and add input to above line, which result should be like below, user input is "test2.newer.com" and i want to add this string |(test2\.newer\.com)
/^From: \s*(.*@)?(((test\.new\.com)|(test2.\newer\.com)))/ REJECT You are not me
i try this but not working
read -p "Enter new domain: " newdomain
file="./testfile"
sed -i "/You are not me/ s/^\(.*\)\())\)/\1, |($newdomain)\2/" $file
how do I go about adding it to the correct position?