UNIXでHTMLバイナリファイルの値を取得および置換する

UNIXでHTMLバイナリファイルの値を取得および置換する

私が作成したHTMLテンプレートから特定の値を検索して置き換えようとしています。バイナリファイルとして、私はこれまでHTMLを検索して置き換えることに成功していませんでした。

ここでは、文字列1111を検索して1234に置き換える必要があります。

style='mso-bookmark:_MailOriginal'><span style='color:#1F497D'>1111</span><o:p></o:p></span></p>

HTMLソースコードに16進数が多すぎるため、どのコマンドを使用できるかをお勧めします。

置き換えたいHTMLは次のとおりです。https://pastebin.mozilla.org/8920460

ベストアンサー1

Pythonで書かれた単純なスクリプトを使って実装することもできます。

.pyの置き換え

f = open("index.html",'r') # open file with read permissions
filedata = f.read() # read contents
f.close() # closes file
filedata = filedata.replace("1111", "1234") # replace 1111 with 1234
filedata = filedata.replace("2222", "2345") # you can add as many replace rules as u need
f = open("index.html",'w') # open the same (or another) file with write permissions
f.write(filedata) # update it replacing the previous strings 
f.close() # closes the file

次に、次を実行します。

python replace.py

おすすめ記事