Replace consecutive delimeters but not single delimeter occurence in unix

31 Views Asked by At

I have an unix file whose delimeter is #!

I need to replace the delimeter '#!' to '~'

But I have '#' as data in some columns. I don't want to replace them.

I want to replace only # and ! together. I don't want to replace when either of them occurs single(only # or only !).

Please help me with a unix command

1

There are 1 best solutions below

1
anacron On BEST ANSWER

You can use the sed command to do replacements.

For example, if your file was data.txt:

sed 's/#!/~/g' data.txt > data_replaced.txt

IF you want to edit the file inplace, you can use this:

sed -i 's/#!/~/g' data.txt

Hope this helps!