Question

I have a datafile that is delimited by \001 or ^A character. So the data looks like this

1234^A This is Ma Baker ^A Gimme all your money ^A \0000123\^A 

I would like to search for the ^A pattern which is actually like \001 in ASCII I could use something like this. I can manage the below e.g.

 sed e/string / substitute 
    \M\a\B\a\k\e\r\s\h\g\a\v\e   |  sed -e 's_\\_\\\\_g' 

But I dont know how to search for the ^A character (I cant see it normally with Cat or view ) and I need to find just those backslashes that precede the ^A. So whats happening here is that - there is a false message sent , to the command that processes the file to ignore ^A as delimiter ( when the delimiter is preceded by the backslash ) when in fact it has to be respected . So I need to double escape the backslash like above to remove the "escape" property of it and treat it like a literal

Was it helpful?

Solution

You can use this sed to match escaped ^A and double escape it:

sed 's~\\\x01~\\&~g'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top