行の一部を16進数に変換

行の一部を16進数に変換

次のファイルがあります。

some line
some other line
DisplayChoices=SAMSUNG
yet another line
ChipManufacturer=LG
and yet another line

(ファイルにはより多くの行があるかもしれませんが、シンボルは=一意であり、操作を実行したい行にのみ表示されます。)

次の文字列を16進表現に変換する必要があるため、=最終的には次のようになります。

some line
some other line
DisplayChoices=53,41,4D,53 (etcetera, hex representation, seperated by comma`s)
yet another line
ChipManufacturer=4C,47
and yet another line

sedとodを試してみましたが役に立ちませんでした。odファイル全体が処理されましたが、指定された文字列のみを変換するだけです。誰もが解決策を知っていますか?

ベストアンサー1

Perlがオプションの場合:

$ perl -lpe 's#(?<==)(.*)#join ",", unpack("H2" x length($1), $1)#e' file
some line
some other line
DisplayChoices=53,41,4d,53,55,4e,47
yet another line
ChipManufacturer=4c,47
and yet another line

この部分は改善することができると信じています...

おすすめ記事