Hadirmu Tidak diundang, Jika ragu-ragu sila pulang!!

Ini blog suka hati aku. Bukan untuk tontonan umum. Kalau engkau masuk ke sini secara tak sengaja, SILA BERAMBUS DENGAN SOPAN sebelum merasa terhina dengan kutukan cacimaki keji dari aku.

Aku dah WARNING!!! Kalau kau nak baca juga, kau WAJIB 100% BERSETUJU dengan apa pun yang aku tulis dan bersumpah setia tak akan mempergunakan apa-apa kandungan blog ini untuk menjahanamkan aku. Jika kau tak bersetuju juga, Sila Pergi Jahanam dan BERAMBUS DENGAN SEGERA sebelum aku cabut urat kentut kau dan menyebabkan kau lumpuh seumur hidup.

Sudahlah, aku taknak membebel lagi. Kalau kau tak faham lagi, sila baca lagi ayat-ayat diatas sampai faham.

Baca lagi ayat diatas...

Khamis, 16 April 2009

Bash scripting with hyperair

the file (combohex.in):

apogee@apogee-ubuntu:~/Code/perl$ cat combohex.in
75 B7 90 BB 69 B5 9A 8B 69 98 66 52 30 00 5C 46 FF 80 80 78 9D 7A 93 85 A5 91
AB 6C 9E 74 8D C8 82 62 83 53 A7 77 79 70 A8 98 97
8E 8D 88 91 79 AD A0 92 81 53 A2 74 94 55 72 64 88
54 7D B0 6E 9F 6A 8B 70 6F 69 74 8A A2 9B 7A 76 90
94 7A 8E 7F 7D 80 8E 86 92 8F 80 9C A1 D1 FB 7F
2D 18 14 29 F6 FF F6 3F A9 48 D0 8C 49 88 53 7B 6E
82 4D 71 BE 6F C0 78 CA 90 B1 6C B3 75 B6 62 C4
84 C4 8D 62 2C 00 47 3F FF 80 80 95 A9 9B A1 7C
99 7E A4 AA A7 60 AA 6F AE 69 99 61 6F 6C 9D 7E
A6 6A 9C 79 96 7F 9A A7 73 A0 5D A1 5F 9E 62 93 42
8A 5D 8B 60 82 62 66 9A 7E A5 86 7E 77 80 86 B2 96
A0 93 85 8D B7 9F 89 97 C4 B9 7F 3B C3 48 A9 7B
CF EF BC 97 51 FA



my perl:

#!/usr/bin/perl
$COMBOHEX = "combohex.in";
open(COMBOHEX);
foreach $hexline () {
chomp($hexline);
@hexes = split(/ /, $hexline);
foreach $hexv (@hexes) {print "0x".$hexv.","}
print "\n";
}
close(COMBOHEX);


hyperair's trick...

apogee@apogee-ubuntu:~/Code/perl$ sed -re 's/([a-fA-F0-9]{2})/0x\1/g' combohex.in
0x75 0xB7 0x90 0xBB 0x69 0xB5 0x9A 0x8B 0x69 0x98 0x66 0x52 0x30 0x00 0x5C 0x46 0xFF 0x80 0x80 0x78 0x9D 0x7A 0x93 0x85 0xA5 0x91
0xAB 0x6C 0x9E 0x74 0x8D 0xC8 0x82 0x62 0x83 0x53 0xA7 0x77 0x79 0x70 0xA8 0x98 0x97
0x8E 0x8D 0x88 0x91 0x79 0xAD 0xA0 0x92 0x81 0x53 0xA2 0x74 0x94 0x55 0x72 0x64 0x88
0x54 0x7D 0xB0 0x6E 0x9F 0x6A 0x8B 0x70 0x6F 0x69 0x74 0x8A 0xA2 0x9B 0x7A 0x76 0x90
0x94 0x7A 0x8E 0x7F 0x7D 0x80 0x8E 0x86 0x92 0x8F 0x80 0x9C 0xA1 0xD1 0xFB 0x7F
0x2D 0x18 0x14 0x29 0xF6 0xFF 0xF6 0x3F 0xA9 0x48 0xD0 0x8C 0x49 0x88 0x53 0x7B 0x6E
0x82 0x4D 0x71 0xBE 0x6F 0xC0 0x78 0xCA 0x90 0xB1 0x6C 0xB3 0x75 0xB6 0x62 0xC4
0x84 0xC4 0x8D 0x62 0x2C 0x00 0x47 0x3F 0xFF 0x80 0x80 0x95 0xA9 0x9B 0xA1 0x7C
0x99 0x7E 0xA4 0xAA 0xA7 0x60 0xAA 0x6F 0xAE 0x69 0x99 0x61 0x6F 0x6C 0x9D 0x7E
0xA6 0x6A 0x9C 0x79 0x96 0x7F 0x9A 0xA7 0x73 0xA0 0x5D 0xA1 0x5F 0x9E 0x62 0x93 0x42
0x8A 0x5D 0x8B 0x60 0x82 0x62 0x66 0x9A 0x7E 0xA5 0x86 0x7E 0x77 0x80 0x86 0xB2 0x96
0xA0 0x93 0x85 0x8D 0xB7 0x9F 0x89 0x97 0xC4 0xB9 0x7F 0x3B 0xC3 0x48 0xA9 0x7B
0xCF 0xEF 0xBC 0x97 0x51 0xFA
apogee@apogee-ubuntu:~/Code/perl$


my mod:

apogee@apogee-ubuntu:~/Code/perl$ sed -re 's/([a-fA-F0-9]{2})\ /0x\1,/g' combohex.in
0x75,0xB7,0x90,0xBB,0x69,0xB5,0x9A,0x8B,0x69,0x98,0x66,0x52,0x30,0x00,0x5C,0x46,0xFF,0x80,0x80,0x78,0x9D,0x7A,0x93,0x85,0xA5,91
0xAB,0x6C,0x9E,0x74,0x8D,0xC8,0x82,0x62,0x83,0x53,0xA7,0x77,0x79,0x70,0xA8,0x98,97
0x8E,0x8D,0x88,0x91,0x79,0xAD,0xA0,0x92,0x81,0x53,0xA2,0x74,0x94,0x55,0x72,0x64,88
0x54,0x7D,0xB0,0x6E,0x9F,0x6A,0x8B,0x70,0x6F,0x69,0x74,0x8A,0xA2,0x9B,0x7A,0x76,90
0x94,0x7A,0x8E,0x7F,0x7D,0x80,0x8E,0x86,0x92,0x8F,0x80,0x9C,0xA1,0xD1,0xFB,7F
0x2D,0x18,0x14,0x29,0xF6,0xFF,0xF6,0x3F,0xA9,0x48,0xD0,0x8C,0x49,0x88,0x53,0x7B,6E
0x82,0x4D,0x71,0xBE,0x6F,0xC0,0x78,0xCA,0x90,0xB1,0x6C,0xB3,0x75,0xB6,0x62,C4
0x84,0xC4,0x8D,0x62,0x2C,0x00,0x47,0x3F,0xFF,0x80,0x80,0x95,0xA9,0x9B,0xA1,7C
0x99,0x7E,0xA4,0xAA,0xA7,0x60,0xAA,0x6F,0xAE,0x69,0x99,0x61,0x6F,0x6C,0x9D,7E
0xA6,0x6A,0x9C,0x79,0x96,0x7F,0x9A,0xA7,0x73,0xA0,0x5D,0xA1,0x5F,0x9E,0x62,0x93,42
0x8A,0x5D,0x8B,0x60,0x82,0x62,0x66,0x9A,0x7E,0xA5,0x86,0x7E,0x77,0x80,0x86,0xB2,96
0xA0,0x93,0x85,0x8D,0xB7,0x9F,0x89,0x97,0xC4,0xB9,0x7F,0x3B,0xC3,0x48,0xA9,7B
0xCF,0xEF,0xBC,0x97,0x51,0xFA,
apogee@apogee-ubuntu:~/Code/perl$


-----
counting commas (by hyperair - 1st version):

apogee@apogee-ubuntu:~/Code/perl$ sed -re 's/[^,]//g' hexcom.in | wc -m
257
apogee@apogee-ubuntu:~/Code/perl$

counting commas (by hyperair - 2nd version):

apogee@apogee-ubuntu:~/Code/perl$ sed -re 's/[^,]//g' hexcom.in| while read line; do echo -n $line; done
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,apogee@apogee-ubuntu:~/Code/perl$


my mod:

apogee@apogee-ubuntu:~/Code/perl$ sed -re 's/[^,]//g' hexcom.in| while read line; do echo -n $line; done | wc -m
233
apogee@apogee-ubuntu:~/Code/perl$



Tiada ulasan:

Catat Ulasan

Nota: Hanya ahli blog ini sahaja yang boleh mencatat ulasan.