what does the < and > at the beginning and at the end of this sed expression mean?
'/<copyright>/d'
Thanks!
CodePudding user response:
that's the string who's sed
searching a match. Everything between the separators, in this case '/', is the string who is searched by sed
command.
CodePudding user response:
The d
command removes all lines matching the preceding regular expression. In this concrete case, it removes all lines containing <copyright>
, no matter where it appears. This is not like the s
replace command where only what was matched is replaced, here the whole line is affected. For example:
$ cat input.txt
1. This is a copyright-protected document.
2. The <copyright> is inside some sort of tag.
3. The "copyright" here is quoted.
4. The copyright is reserved.
5. XcopyrightY is not a word.
$ sed '/<copyright>/d' < input.txt
1. This is a copyright-protected document.
3. The "copyright" here is quoted.
4. The copyright is reserved.
5. XcopyrightY is not a word.
As you can see, only line 2 was removed, because it is the only line matching the search expression (regex).
By the way, literal <
and >
characters are not to be mistaken for the regex extensions \<
and \>
which match word boundaries. For example:
$ sed '/\<copyright\>/d' < input.txt
5. XcopyrightY is not a word.
$ sed 's/\<copyright\>/(c)/g' < input.txt
1. This is a (c)-protected document.
2. The <(c)> is inside some sort of tag.
3. The "(c)" here is quoted.
4. The (c) is reserved.
5. XcopyrightY is not a word.