views:

427

answers:

1

I need to parse a file using windows batch scripts and replace all occurences of backspace (^H) with any other delimiter like tab. I searched in several forums but couldn't find a proper solution. Any ideas are most welcome.

+1  A: 

This can't be using pure batch syntax. I think you're best of using a command line program like this one: FART.

Pekka
HAHAHAHA FART +1
Hamish Grubijan
I am trying to use "fart expdata.dat \b K". Basically I am trying to find a backspace character in my file expdata.dat and replace it with 'K'. But fart is not able to do it. It gives the following message"Replaced 0 occurence(s) in 0 file(s)."How to put a backspace in a file? I tried to put it by pressing the backspace key in my keybaord. That goes and deletes a character in the file but I am expecting that now my file contains a backspace character.
Harsha
Odd, it seems to be able to handle backspaces, and seems to resolve them in the source code. You could try putting the character into quotes, and try a double backspace \\b. Are you doing this directly from the command line? If it doesn't work when called directly from command line, I'm afraid you'll have to find another tool.
Pekka
And have you tried fart's verbose mode?
Pekka
Yes I tried by giving the following command :fart -V expdata.dat "\b" Kand the output I got is :FART: --verboseFART: wild_card="expdata.dat"FART: find_string="\b"FART: replace_string="K"FART: processing ,expdata.datReplaced 0 occurence(s) in 0 file(s).
Harsha
How to put a backspace character in file? How does it look?
Harsha
The \b should do just fine, there is probably no other way to type in a backspace. You are 100% sure there are backspace characters in the file? Can you try a file with different characters like tabulators?
Pekka
I am able to do it now using the following:fart -V -B -C --backup myfile.txt \b KDo you know of any way to parse such a file using bcp tool ?
Harsha
What does the backup switch in fart do?
Pekka
Since this is a binary file, fart does not make changes to it without the --backup option.
Harsha
I see. No, I don't know how to parse those files, sorry. If FART doesn't work out for you here is another question with a few pointers: http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-enviro I don't know which ones work with backspaces, you'd have to test.
Pekka