sed
is indeed the right tool for this job, with its s
command (the one that's used the most).
Wildcards for file names in the shell, and regular expressions in tools such as grep
and sed
, have a different syntax. See Why does my regular expression work in X but not in Y? for a summary of the differences.
In the text to replace, [
is a regular expression special character; the other characters stand for themselves. Since it's a special character, it needs to be written as \[
(the backslash makes the next character stand for itself instead of having its special meaning).
A sequence of digits is [0-9]*
: [0-9]
means “any digit”, and *
means “repeat the preceding character or character set 0 or more times”.
Thus:
sed 's/" rel="lightbox\[[0-9]]" title="/#/' <old-file >new-file
The single quotes make the shell pass everything in between literally to the sed
command.
sed
doesn't do "wildcards", it does regular expressions. they are very different (see http://unix.stackexchange.com/questions/57957/how-do-regular-expressions-differ-from-wildcards-used-to-filter-files). Also, it looks like you're trying to parse/edit HTML or XML. Don't use sed (or any other regex based tool), use an XML or HTML parser instead. – cas Apr 10 '16 at 01:04