4
$\begingroup$

enter image description here

This is my data file, each line was separated by SOH, maybe hex \x001,

I've tried some options of ReadList, and Import.

ReadList[file,"Record"]

enter image description here

Well, the problem is not don't know RecordSeparators, but what separator character is for SOH.

Luckily, I found one method, Copy SOH into somewhere [address bar/Text Cell], and then you'll see a empty box. Show CellExpression of the Text Cell, then you'll see

"\.01" that's the right separator

$\endgroup$
2
  • $\begingroup$ See the docs for ReadList[ ... , RecordSparators->...] $\endgroup$ Nov 25, 2014 at 4:16
  • $\begingroup$ @belisarius Hi, first time, I don't know what's the right separator, now I know that's \.01 $\endgroup$ Nov 25, 2014 at 4:24

2 Answers 2

4
$\begingroup$

This works. Use BinaryReadList and remove binary 1 which is code for SOH, then convert back to string

make file

>echo -e "2014111\x01ab6f2ed5\x01ce34cbef" > file.txt

Mathematica graphics

Go to Mathematica and type

SetDirectory[NotebookDirectory[]];
data = BinaryReadList["file.txt"]
data = SplitBy[data, (# != 1 && # != 10) &]
data = DeleteCases[data, {1} | {10}]  (*SOH and \n removed*)
r = FromCharacterCode[#] & /@ data

Mathematica graphics

FullForm[r]

Mathematica graphics

$\endgroup$
4
$\begingroup$
ReadList[StringToStream@"2014111\\.01ab6f2ed5\\.01ce34cbef", Record, RecordSeparators -> "\\.01"]

(*{"2014111", "ab6f2ed5", "ce34cbef"}*)

Remove one slash after copying to your notebook for testing.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.