【求助】sed script

【求助】sed script

问题:
如果有一个文件包含:
s23432(学生证号码)
s1232
123.tom.com
234.tom.com
ss.tom.com(特殊情况)
[email="s123@tom.com"]s123@tom.com[/email]
[email="s435654@tom.com"]s435654@tom.com[/email]

如果要写一个sed script 要将所有学生证号码如果开始是小写s将变成大写S然后将数字不过8位的就在前面补0,例如s123就要变成S00000123 并且将所有 tom.com 变成163.net

请教各位高手帮忙写个sed script
谢谢      
seems like it's a little difficult for sed to do that. try perl.      
3432(学生证号码)
s1232
123.tom.com
234.tom.com
ss.tom.com(特殊情况)
[email="s123@tom.com"]s123@tom.com[/email]
[email="s435654@tom.com"]s435654@tom.com[/email]

我想可以用sed来做s->S ,tom.com ->163.com,
用awk的printf 来打印数字,      
it is the assignment requirement, no other choice
it says only use the s(substitute) sed command .      
复制内容到剪贴板
代码:
[color=blue]-(guest@mac:tty1)-(tmp)-
[18736 0] %[/color] cat file
s23432
s1232
123.tom.com
234.tom.com
ss.tom.com
[email]s123@tom.com[/email]
[email]s435654@tom.com[/email]
[color=blue]-(guest@mac:tty1)-(tmp)-
[18736 0] %[/color] cat foo.sed

/^s[0-9]\+$/ {
   :loop
   /s[0-9]\{8,8\}$/b next
   s/s/s0/
   b loop
}

:next
s/tom\.com/163.net/
[color=blue]-(guest@mac:tty1)-(tmp)-
[18736 0] %[/color] sed -f foo.sed file
s00023432
s00001232
123.163.net
234.163.net
ss.163.net
[email]s123@163.net[/email]
[email]s435654@163.net[/email]
[color=blue]-(guest@mac:tty1)-(tmp)-
[18736 0] %[/color]
      
复制内容到剪贴板
代码:
[color=blue]-(guest@mac:tty1)-(tmp)-
[18736 0] %[/color] cat file
s23432
s1232
123.tom.com
234.tom.com
ss.tom.com
[email]s123@tom.com[/email]
[email]s435654@tom.com[/email]
[color=blue]-(guest@mac:tty1)-(tmp)-
[18736 0] %[/color] cat foo.sed

s/^s\([0-9]\{1,1\}\)$/s0\1/
s/^s\([0-9]\{2,2\}\)$/s0\1/
s/^s\([0-9]\{3,3\}\)$/s0\1/
s/^s\([0-9]\{4,4\}\)$/s0\1/
s/^s\([0-9]\{5,5\}\)$/s0\1/
s/^s\([0-9]\{6,6\}\)$/s0\1/
s/^s\([0-9]\{7,7\}\)$/s0\1/
s/^s\([0-9]\{8,8\}\)$/S\1/
s/tom\.com/163.net/
[color=blue]-(guest@mac:tty1)-(tmp)-
[18736 0] %[/color] sed -f foo.sed file
S00023432
S00001232
123.163.net
234.163.net
ss.163.net
[email]s123@163.net[/email]
[email]s435654@163.net[/email]
[color=blue]-(guest@mac:tty1)-(tmp)-
[18736 0] %[/color]
      
多谢版主帮助。
但是
[email="s123@163.net"]s123@163.net[/email]
[email="s435654@163.net"]s435654@163.net[/email]
前面s123  和 s435654 并没有变化。。请问应该怎样解决呢?      
you asked to much seems like you know nothing about sed you better refer to sed's manual       
yes, because i am learning haskell at the moment, the teacher give a sed program question ask me to do the research...but any way i try it myself      
你可以解析一下下面的句子吗?
s/^s\([0-9]\{1,1\}\)$/s0\1/