Just for clarity:
Code:
#!/bin/sh
for file in ./*.html
do echo $file
sed -e 's_<font color="#800000"> <a name="[0-9]"></a>'__g -e s_'<font color="#800000"> <a name="[0-9][0-9]"></a>__g' "$file" >"$file"_new
done
exit
Becomes:
Code:
#!/bin/sh
for file in ./*.html
do echo $file
sed -e 's_<font color="#800000"> <a name="[0-9]"></a>'__g -e s_'<font color="#800000"> <a name="[0-9][0-9]"></a>__g' -e 's_\[[1-9]\]\ \[<a href="#top">crtc</a>\]__g' -e 's_\[[1-9][1-9]\]\ \[<a href="#top">crtc</a>\]__g' "$file" >"$file"_new
done
exit
You can do it with four sed statements, but then you would have to create 4 new files, with the forth file being the last, fully changed document. It causes unnecessary disk writing and adds time to the process not needed (especially if you are working with a few hundred or thousand files)
Cherz
Just to explain what happens, as I see you actualy tried to use some initiative:
In sed you can spesify a range for a value using square brackets.
So [1-5] will match, 1, 2, 3, 4 or 5
However it is NOT a numeral range so [5-10] will NOT match 5, 6, 7, 8, 9, 10.. It will Match 0, 1, 5, 6, 7, 8, 9.
Typing [12345] and [1-5] is synonymous.
In the given statement there are already square brackets:
[25] so we need to tell sed to KEEP the brackets, and give it a patern range, so we escape the last set of square brackets:
\[[1-5]\]. This tells sed to match [1], [2], [3], [4], [5].
To match dubble digtits, like 10, 12, 55 etc, we need to give 2 ranges (one for each number):
So [1-2][1-2] will match: 11, 12, 21, 22.
To understand that, play with echo and a range {1..9} in terminal and see how it works:
Code:
echo {1..9}
echo {1..9}{1..9}
You will note however you can simply say
To have the same result as the second echo in the first example. But the value range in sed does not follow the same behaviour. If it is possible to have a range in sed similar to {1..99}, then I am unaware of HOW to do it.
Hope this clears things up a bit
Cherz
Bookmarks