2

背景:MS 向存在严重磨损问题的 OEM 发布 COA 标签。使用的碳粉未正确粘合到 COA 贴纸的纸张上。随着时间的推移,产品密钥会降级并且某些字母/数字不再可读,从而禁止输入授权密钥进行重新安装。

问题:当只有几个字母/数字损坏时,尝试确定之前尝试过的数字是非常令人沮丧的。

请求:利用 sed 或 awk(最好)或其他方法输入 STRING,例如

A{B,E,R,8}CDE-FGH{I,1}J-KLMN{O,Q,0}-PQRST-UVWXY

并接收输出

ABCDE-FGHIJ-KLMNO-PQRST-UVWXY
AECDE-FGHIJ-KLMNO-PQRST-UVWXY
ARCDE-FGHIJ-KLMNO-PQRST-UVWXY
A8CDE-FGHIJ-KLMNO-PQRST-UVWXY
ABCDE-FGH1J-KLMNO-PQRST-UVWXY
AECDE-FGH1J-KLMNO-PQRST-UVWXY
ARCDE-FGH1J-KLMNO-PQRST-UVWXY
A8CDE-FGH1J-KLMNO-PQRST-UVWXY
ABCDE-FGHIJ-KLMNQ-PQRST-UVWXY
AECDE-FGHIJ-KLMNQ-PQRST-UVWXY
ARCDE-FGHIJ-KLMNQ-PQRST-UVWXY
A8CDE-FGHIJ-KLMNQ-PQRST-UVWXY
ABCDE-FGH1J-KLMNQ-PQRST-UVWXY
AECDE-FGH1J-KLMNQ-PQRST-UVWXY
ARCDE-FGH1J-KLMNQ-PQRST-UVWXY
A8CDE-FGH1J-KLMNQ-PQRST-UVWXY
ABCDE-FGHIJ-KLMN0-PQRST-UVWXY
AECDE-FGHIJ-KLMN0-PQRST-UVWXY
ARCDE-FGHIJ-KLMN0-PQRST-UVWXY
A8CDE-FGHIJ-KLMN0-PQRST-UVWXY
ABCDE-FGH1J-KLMN0-PQRST-UVWXY
AECDE-FGH1J-KLMN0-PQRST-UVWXY
ARCDE-FGH1J-KLMN0-PQRST-UVWXY
A8CDE-FGH1J-KLMN0-PQRST-UVWXY
4

2 回答 2

5

did you try this on the command line? at least in bash, it "just works":

> echo A{B,E,R,8}CDE-FGH{I,1}J-KLMN{O,Q,0}-P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N0-PQRST-UVWXY
AECDE-FGH1J-KLMNO-PQRST-UVWXY
AECDE-FGH1J-KLMNQ-PQRST-UVWXY
AECDE-FGH1J-KLMN0-PQRST-UVWXY
ARCDE-FGHIJ-KLMNO-PQRST-UVWXY
ARCDE-FGHIJ-KLMNQ-PQRST-UVWXY
ARCDE-FGHIJ-KLMN0-PQRST-UVWXY
ARCDE-FGH1J-KLMNO-PQRST-UVWXY
ARCDE-FGH1J-KLMNQ-PQRST-UVWXY
ARCDE-FGH1J-KLMN0-PQRST-UVWXY
A8CDE-FGHIJ-KLMNO-PQRST-UVWXY
A8CDE-FGHIJ-KLMNQ-PQRST-UVWXY
A8CDE-FGHIJ-KLMN0-PQRST-UVWXY
A8CDE-FGH1J-KLMNO-PQRST-UVWXY
A8CDE-FGH1J-KLMNQ-PQRST-UVWXY
A8CDE-FGH1J-KLMN0-PQRST-UVWXY

or maybe you already knew this and need sed/awk for some other reason?

于 2012-05-26T00:09:22.807 回答
0

I'd probably pick Ruby, Python, or Perl for this instead. And if it were just for me, I'd do something super-cheap and use a series of nested for loops like the following pseudo-code:

string = "A%sCDE-FGH%sJ-KLMN%s-PQRST-UVWXY"

for a in ["B", "E", "R", "8"]
  for b in ["I", "1"]
    for c in ["O" "Q", "0"]
        printf string, a, b, c
    end
  end
end

The downside is you'd need to replace the string, the list of characters in each for loop, and potentially add or remove for loops based on the number of unknown characters. Making it a more powerful tool as you've described would definitely take more effort, but might make all the difference if you're trying to make a tool for others to use.

于 2012-05-26T00:06:44.220 回答