• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

How exactly does sed view meta characters when you replace or delete text?

null_reflections

Well-Known Coder
I'm trying to figure out how to use sed without erasing extra things that i want to keep in the document. So far, i've realized that sed is largely user-friendly in terms of how it does away with strings and numbers:

Code:
sed -i '/cow/d' <file>

sed -i '/10/d' <file>

in both of these examples, sed will only get rid of entire instances of "10" and "cow", and will not erase every 1,0,c,o,w. However, it doesn't work this way with metacharacters. Let's say i had "**" in a document that i wanted to erase, how do i do that without getting rid of every asterisk? For some reason, it erases all the test in the document when i do
Code:
sed -i '/**/d' <file>
, is it just reverting to the bash wildcard? Why does it do that?

Just to be clear, this works just fine if i wanted to get rid of all the asterisks for some reason:
Code:
sed -i '/*/d' <file>
 
Last edited:
Solution
I've answered part of this: you can edit separate strings in sed like this, and it works if you have two ** in a file but only want to get rid of that particular string:

Code:
sed -i '/*\|*/d' <file>

However, i still wonder why sed erases all the text in my file when i have the two asterisks next to each other.

null_reflections

Well-Known Coder
I've answered part of this: you can edit separate strings in sed like this, and it works if you have two ** in a file but only want to get rid of that particular string:

Code:
sed -i '/*\|*/d' <file>

However, i still wonder why sed erases all the text in my file when i have the two asterisks next to each other.
 
Solution
Top