Skip to main content
added 2 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
$ sed 's/^.*[[:<:]]Host[[:>:]].*$/replacement text/' file.intxt

The above will replace every line in the file file.intxt 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).

$ sed 's/^.*[[:<:]]Host[[:>:]].*$/replacement text/' file.in

The above will replace every line in the file file.in 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).

$ sed 's/^.*[[:<:]]Host[[:>:]].*$/replacement text/' file.txt

The 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).

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

$ sed 's/^.*[[:<:]]Host[[:>:]].*$/replacement text/' file.in

The above will replace every line in the file file.in 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).