I have this line that I want to use sed on:
--> ASD = $start ( *.cpp ) <--
where $start is not a varaiable, I want to use sed on it and replace all this line with:
ASD = $dsadad ( .cpp )
How can I make sed ignore special charactars, I tried adding back slash before special characters, but maybe I got it wrong, can some one show me an example?
Here is what i want :
sed 's/CPPS = \$(shell ls | grep \*\.cpp )/somereplace/' Makefile
\ followed by a letter has a special meaning (special characters) in some implementations, and \ followed by some other character means \c or c depending on the implementation. With single quotes around the argument ( sed 's/…/…/' ), use '\'' to put a single quote in the replacement text.
Special Regex Characters: These characters have special meaning in regex (to be discussed below): . , + , * , ? , ^ , $ , ( , ) , [ , ] , { , } , | , \ . Escape Sequences (\char): To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \.
The reason is that a dot is a special character in regular expressions. If you mean an actual dot, you need to escape it with \.
sed 's/\$start/\$dsadad/g' your_file
>> ASD = $dsadad ( *.cpp )
sed 's/\*//g' your_file
>> ASD = $start ( .cpp )
To follow your edit :
sed -i 's/ASD = \$start ( \*.cpp )/ASD = \$dsadad ( .cpp )/' somefile
>> ASD = $dsadad ( .cpp )
Add the -i (--inplace) to edit the input 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