我有一條語句需要替換。原來的格式是這樣的:用shell腳本替換另一個語句
f.STRING.focus();
凡STRING
是[:alpha:]
和[:digit:]
(正則表達式)的組合。 我的目的是將其更改爲
highlight("STRING");
例如:
f.abCDef12345.focus() ---> highlight("abCDef12345");
f.ip2.focus() ---> highlight("ip2");
我可以輕鬆地使用sed
更換聲明數百HTML文件。但是,我不知道如何在shell腳本中獲得STRING
。
過程可以描述如下:
For each html:
For the STRING which matches the pattern:
1. Assign it to a parameter.
2. Insert that STRING to highlight("STRING");
3. Replace the old one "f.STRING.focus();" to "highlight("STRING");"
但我不知道如何把它們寫在shell腳本...任何暗示表示讚賞。
更新時間:
- 請清楚地描述你的腳本。太謝謝你了!
- 抱歉的錯誤!
STRING
是和[:alpha:]
和[:digit:]
的組合。所以這裏提到的例子f.ip2.focus()
可以說得通。
你能不能只是在多個文件上使用sed和regexp?我不確定我是否正確地得到了這個想法。 – dstronczak