I'm looking to match all less than ('<') or greater than ('>') signs in a file using sed. I only want to match the single character
My goal is to replace them with ' <'
and '> '
(ensure they have white space around them so I can parse them easier) respectively.
For example, it would match:
(without space within the tags)
< p >Hey this is a paragraph.< /p >< p >And here is another.< /p >
.. and turn it into (note the spaces)
< p > Hey this is a paragraph. < /p > < p > And here is another. < /p >
Here's what my initial (wrong) guess was:
sed 's/<{1}|>{1}/ <> /' ...
It matches the whole word/line, which is not desired, and it also does not replace correctly.
Anyways, any help would be appreciated! Thanks!
Matches any single character in list : for example, [aeiou] matches all vowels. A list may include sequences like char1 - char2 , which matches any character between (inclusive) char1 and char2 . A leading ^ reverses the meaning of list , so that it matches any single character not in list .
Regular expressions are used by several different Unix commands, including ed, sed, awk, grep, and to a more limited extent, vi.
The sed command is a common Linux command-line text processing utility. It's pretty convenient to process text files using this command. However, sometimes, the text we want the sed command to process is not in a file. Instead, it can be a literal string or saved in a shell variable.
Try two substitutions to make it easier:
sed 's/</ </g ; s/>/> /g' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With