I've got a problem with some regular expression in sed.I want to change a line in my file, so I did it like that:sed -i '3s/.*/my new text in file/' file.txt. This extension is looking for 3rd line in a file and change it.This solution isn't good but I don't know how to build a good regular extension. Let's say that I am looking for the word 'Host' in some file. How to build a good regular extension? I have tried the following:sed -e '<\H...s>\ /my new text in file/' file.txt'. What am I doing wrong?
Sed and Regular Expressions
sed;regular expression
$ sed 's/^.*[[:<:]]Host[[:>:]].*$/replacement text/' file.txtThe above will replace every line in the file file.txt that contains the word Host with the string replacement text. The result will be given on standard output.The [[:<:]] is a zero-length pattern that matches at the beginning of a word. Similarly, [[:>:]] will match at the end of a word.  This means that the above substitution will not replace a line with the word Hostname or xHost on it (unless the word Host appears elsewhere on the line).