Sorry, I haven't been able to hobble this together...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sorry, I haven't been able to hobble this together...
# 1  
Old 11-06-2014
Sorry, I haven't been able to hobble this together...

I have a file containing about 100 lines, each with a ';' the end.

Each line is a string represented in UTF-16 hex and they vary in length.

I am thinking I ought to be able to use (g)awk to insert ',00,' after each two characters on each line in the file so that in the end, I have a comma-delimited UTF-16LE hex file:

From:
Code:
224C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73656374657475722061646970697363696E6720656C69742E2050656C6C656E74657371756520697073756D206D617373612200;
224C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73656374657475722061646970697363696E6720656C69742E2050656C6C656E74657371756520697073756D206D617373612200;

To:
Code:
22,00,4C,00,6F,00,72,00,65,00,6D,00,20,00,69,00,70,00,73,00,75,00,6D,00,20,00,64,00,6F,00,6C,00,6F,00,72,00,20,00,73,00,69,00,74,00,20,00,61,00,6D,00,65,00,74,00,2C,00,20,00,63,00,6F,00,6E,00,73,00,65,00,63,00,74,00,65,00,74,00,75,00,72,00,20,00,61,00,64,69,00,70,00,69,00,73,00,63,00,69,00,6E,00,67,00,20,00,65,00,6C,00,69,00,74,00,2E,00,20,00,50,00,65,00,6C,00,6C,00,65,00,6E,00,74,00,65,00,73,00,71,00,75,00,65,00,20,00,69,00,70,00,73,00,75,00,6D,00,20,00,6D,00,61,00,73,00,73,00,61,00,22,00,00;
22,00,4C,00,6F,00,72,00,65,00,6D,00,20,00,69,00,70,00,73,00,75,00,6D,00,20,00,64,00,6F,00,6C,00,6F,00,72,00,20,00,73,00,69,00,74,00,20,00,61,00,6D,00,65,00,74,00,2C,00,20,00,63,00,6F,00,6E,00,73,00,65,00,63,00,74,00,65,00,74,00,75,00,72,00,20,00,61,00,64,69,00,70,00,69,00,73,00,63,00,69,00,6E,00,67,00,20,00,65,00,6C,00,69,00,74,00,2E,00,20,00,50,00,65,00,6C,00,6C,00,65,00,6E,00,74,00,65,00,73,00,71,00,75,00,65,00,20,00,69,00,70,00,73,00,75,00,6D,00,20,00,6D,00,61,00,73,00,73,00,61,00,22,00,00;

I've fiddled around all day (on and off) and have nothing to show for my efforts. If any of you can show me the way, I'd be most appreciative.

Thanks,

gus

Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 11-06-2014 at 10:37 PM.. Reason: code tags
# 2  
Old 11-06-2014
This could be done with awk, but you don't need that much power for this. A simple editor (e.g., ed, ex, sed, or vi is all you need for this. Here is an example using sed:
Code:
sed 's/../&,00,/g; s/,;/;/' input

After massaging your sample input and output to get rid of spaces in the middle of your lines (since you didn't use CODE tags), I also found that this code does not produce the sample output you said you want; you're missing a ,00 close to the end of each line and a ,00, in the middle of the line.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 11-07-2014
Please be aware that the result is NOT a UTF-16LE file, but sort of a textual representation of such. Hexdump of . . .
UTF-16LE:
Code:
00000000  22 00 4c 00 6f 00 72 00  65 00 6d 00 0a 00        |".L.o.r.e.m...|

Your text:
Code:
00000000  32 32 2c 30 30 2c 34 43  2c 30 30 2c 36 46 2c 30  |22,00,4C,00,6F,0|
00000010  30 2c 37 32 2c 30 30 2c  36 35 2c 30 30 2c 36 44  |0,72,00,65,00,6D|
00000020  2c 30 30 2c 0a                                    |,00,.|

# 4  
Old 11-07-2014
Thank you Rudi - I must have the incorrect term for what I said I wanted because the output the sedcode Mr. Cragun provided works as I needed it to.

Last edited by gusbrown; 11-07-2014 at 09:33 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I thought I asked the question before but I haven't sorry

:D could any one answer my previous question... just looked through logg and found no such question that I had asked.. please any input would help \.. :confused: (2 Replies)
Discussion started by: moxxx68
2 Replies

2. UNIX for Dummies Questions & Answers

haven`t the right of root?

I install solaris 8. I want to use netconfig command, but it dispear "you haven`t the right",why? Is there somebody can help me? (3 Replies)
Discussion started by: yycokr
3 Replies
Login or Register to Ask a Question