2

Anyway to simplify these two into one:

temp=${i//[/\\[}
temp=${temp//]/\\]}

input:

i[1]
i[2]

output:

i\[1\]
i\[2\]
1
  • I don't think so. The parameter in ${param/pattern/string} has to be a parameter name, it can't be an expression. Commented Apr 10, 2013 at 20:43

1 Answer 1

1
sed 's/[][]/\\&/g' foo.txt
  • in each line look for [ or ]
  • put \ before each occurance
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.