1

eg. txtfile is just [

sed -i 's/[/linux/' txtfile (this gives an error unbalanced brackets ([])) after running the command I wanted to replace [ to linux

I tried \\ at the front, but I don't think it is correct and searched a while couldn't find anything useful. Thanks

olo
  • 131

1 Answers1

10

All you need is escape the [ using \:

sed -i 's/\[/linux/' txtfile

For completeness, another alternative is to put that [ inside a [...] bracket expression:

sed -i 's/[[]/linux/' txtfile
GMaster
  • 6,322