开发者

Appending a file using sed command

I have a file which contains something like that:

0x0a ,0x63 ,0x31 ,0x38 ,30
0x6b ,0x5f ,0x6c ,0x69 ,6d
0x0a ,0x63 ,0x31 ,0x38 ,30
0x6b ,0x5f ,0x6c ,0x69 ,6d
0x69 ,0x74 ,0a

What I want to do is to use sed (or a diff开发者_运维问答erent command) for appending a 0x in front of the last hex number of each line and also a comma , at the end of each line. That is, for the above code snippet, I want that:

0x0a ,0x63 ,0x31 ,0x38 ,0x30,
0x6b ,0x5f ,0x6c ,0x69 ,0x6d,
0x0a ,0x63 ,0x31 ,0x38 ,0x30,
0x6b ,0x5f ,0x6c ,0x69 ,0x6d,
0x69 ,0x74 ,0x0a,

I want that replacement to start from the beginning of the file until an empty line is detected.

Thanks in advance for any help.


 cat somefile | sed 's/,\([0-9a-f]*\)$/,0x\1,/'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜