1

Please tell me how to replace / with ; in this:

ASAL
/*
 * VIEW: VINAME1 
 */
Create view viewname
/
test

I need to convert only the lone /, so the output should be like this:

ASAL
/*
 * VIEW: VINAME1 
 */
Create view viewname
;
test
3

It's a / between the start and the end of the line. As a regex that's ^/$:

 sed 's|^/$|;|' your_file
| improve this answer | |
  • Maybe you should allow whitespace around the slash? – Byte Commander Sep 29 '16 at 23:34
  • How to add space and tab also in this – asalthangam Sep 29 '16 at 23:59
  • @asalthangam I cover whitespace in my answer. BTW, please accept the answer that helped you most by clicking the check mark on the left side. (Not saying it's mine, but it's definitely mine :-P ) – wjandrea Nov 28 '16 at 1:26
2

This identifies the slash as being the only character in the line:

sed 's.^/$.;.g'

Caret indicates start of line, dollar indicates end of line.

Edit: To allow for whitespace before and after the slash, and delete it:

sed -r 's.^(\s)?/(\s)?$.;.'

Edit 2: To allow for whitespace and not delete it:

sed -r '/^(\s)?\/(\s)?$/ s./.;.'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.