Reputation: 65
How would I be able to delete single line comments starting with /*......*/
and
By anywhere I mean it can be in a line by itself or after some equation for example.
I was thinking something along the lines of :
s/\/\*.*\*\///g'
Upvotes: 3
Views: 920
Reputation: 5298
sed -e 's|/\*.*\*/||g' => to remove /* ... */
sed -e 's|//.*||g' => to remove //...
sed -e 's|/\*.*\*/||g' -e 's|//.*||g' => to remove both /* ... */ and //...
Example:
sdlcb@ubuntu:~$ cat file
jksdjskjdsd /* jdskdskd */
jdskdjsd // ksldksldsdks
uiiu
sdlcb@ubuntu:~$ sed -e 's|/\*.*\*/||g' -e 's|//.*||g' file
jksdjskjdsd
jdskdjsd
uiiu
Upvotes: 3
Reputation: 84561
Or if you don't like the picket fence look, you can change the separator and also use character classes to prevent having to escape everything:
's|/[*].*[*]/||g'
Note: allowable separator replacement varies slightly by OS.
Upvotes: 2