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.
Asked
Active
Viewed 1,836 times
0
-
No, power shell is not an option. I just need to do it using only windows commands. Ideally I would like to do it using a tool like bcp but couldn't find a way. Hence I am trying to do it through windows batch script – Thunderhashy Dec 30 '09 at 23:08
1 Answers
1
This can't be using pure batch syntax. I think you're best of using a command line program like this one: FART.

Pekka
- 442,112
- 142
- 972
- 1,088
-
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. – Thunderhashy Dec 30 '09 at 23:06
-
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 Dec 30 '09 at 23:13
-
Yes I tried by giving the following command : fart -V expdata.dat "\b" K and the output I got is : FART: --verbose FART: wild_card="expdata.dat" FART: find_string="\b" FART: replace_string="K" FART: processing ,expdata.dat Replaced 0 occurence(s) in 0 file(s). – Thunderhashy Dec 30 '09 at 23:48
-
-
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 Dec 31 '09 at 00:11
-
I am able to do it now using the following: fart -V -B -C --backup myfile.txt \b K Do you know of any way to parse such a file using bcp tool ? – Thunderhashy Dec 31 '09 at 01:49
-
-
Since this is a binary file, fart does not make changes to it without the --backup option. – Thunderhashy Dec 31 '09 at 19:13
-
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 Dec 31 '09 at 20:24