# .bat to edit large .txt file



## mark14 (Jul 15, 2009)

Hi all

I have a large .txt file containing xyz data. unfortunately the decimal places in column x and y are in the wrong place to use in GMT. The file is too large (500mb) to edit in excel/wordpad/notepad. Is it possible to use a .bat to move the decimal place in columns x and y 4 places to the right??

Any help would be grand!

Thanks

Mark


----------



## Squashman (Apr 14, 2005)

Could you give us an example of the input and what you want the output to look like.


----------



## mark14 (Jul 15, 2009)

input file looks like

565000.00 7445555.00 1500.00

output file needs to look like

56.500000 74.45555.00 1500.00

There are approx 500,000 to 1,000,000 lines in a file


----------



## Stu_computer (Jul 7, 2005)

here's a utility i made that does what you described, doesn't do anything else though.

there were a few trialware that do similar, but didn't find any freeware versions, maybe i'll make a generic windows version that has user input for find/replace and delete/insert catagories.

for a batch file a sample like:
565000.00 7445555.00 1500.01
565000.00 7445555.00 1500.02
565000.00 7445555.00 1500.03
565000.00 7445555.00 1500.04
565000.00 7445555.00 1500.05
565000.00 7445555.00 1500.06
565000.00 7445555.00 1500.07
565000.00 7445555.00 1500.08
565000.00 7445555.00 1500.09
565000.00 7445555.00 1500.10

can be stripped of spaces and periods easily

```
@echo off
FOR /F "usebackq tokens=1,2,3,4* delims=." %%A IN ("sample_file.txt") DO (
FOR /F "tokens=1,2,3 " %%F IN ("%%A%%B%%C%%D") DO @echo %%F%%G%%H)
```

56500000744555500150001
56500000744555500150002
56500000744555500150003
56500000744555500150004
56500000744555500150005
56500000744555500150006
56500000744555500150007
56500000744555500150008
56500000744555500150009
56500000744555500150010

but after that inserting character/position gets rather involved...was easier to whip up a utility prog. :grin:

(note: the zip file is password protected mark sent to you in a pm.)


----------



## TheOutcaste (Mar 19, 2009)

mark14 said:


> move the decimal place in columns x and y 4 places to the right??


I'm guessing you mean to the left?



mark14 said:


> input file looks like
> 
> 565000.00 7445555.00 1500.00
> 
> ...


You moved column Y *5* places in your output, not 4, and left the original decimal in place.
Moving it 4 places would look like this:

56.500000 744.555500 1500.00
So, do you need to move it 4 places to the left, or do you need Columns X and Y to have 2 digits, the Decimal, then the rest of the digits?
This code will do either, just choose your output line and remove the one you don't need:

```
@Echo %dbg%Off
SetLocal EnableDelayedExpansion
Set _InFile=Sample.txt
Set _OutFile1=Fixed1.txt
Set _OutFile2=Fixed2.txt
If Exist %_OutFile1% Del %_OutFile1%
If Exist %_OutFile2% Del %_OutFile2%
For /F "Usebackq Tokens=1-4* Delims=. " %%I In ("%_InFile%") Do (
Set _P1=%%I
Set _P2=%%K
:: This line moves Decimal 4 places to the left
>>"%_OutFile1%" Echo !_P1:~0,-4!.!_P1:~-4!%%J !_P2:~0,-4!.!_P2:~-4!%%L %%M
:: This line places Decimal after the 1st 2 digits
>>"%_OutFile2%" Echo !_P1:~0,2!.!_P1:~2!%%J !_P2:~0,2!.!_P2:~2!%%L %%M
)
```
Here's the Sample input, and the two output files:

```
Sample.txt
65000.00 45050.00 1500.01
69500.00 55600.00 1500.02
74000.00 66150.00 1500.03
78500.00 76700.00 1500.04
83000.00 87250.00 1500.05
87500.00 97800.00 1500.06
92000.00 108350.00 1500.07
96500.00 118900.00 1500.08
101000.00 129450.00 1500.09
105500.00 140000.00 1500.10
565000.00 7445555.00 1500.00

Fixed1.txt - Moves 4 places to the left. 
6.500000 4.505000 1500.01
6.950000 5.560000 1500.02
7.400000 6.615000 1500.03
7.850000 7.670000 1500.04
8.300000 8.725000 1500.05
8.750000 9.780000 1500.06
9.200000 10.835000 1500.07
9.650000 11.890000 1500.08
10.100000 12.945000 1500.09
10.550000 14.000000 1500.10
56.500000 744.555500 1500.00

Fixed2.txt - Always 2 digits then the decimal
65.00000 45.05000 1500.01
69.50000 55.60000 1500.02
74.00000 66.15000 1500.03
78.50000 76.70000 1500.04
83.00000 87.25000 1500.05
87.50000 97.80000 1500.06
92.00000 10.835000 1500.07
96.50000 11.890000 1500.08
10.100000 12.945000 1500.09
10.550000 14.000000 1500.10
56.500000 74.4555500 1500.00
```


----------



## mark14 (Jul 15, 2009)

thanks everyone. they all work! also managed it using 'awk' on linux machine. can't believe how much easier that turned out to be over windows!


----------



## Squashman (Apr 14, 2005)

You can get most of the Linux stuff on your Windows PC.
http://unxutils.sourceforge.net/
or
http://gnuwin32.sourceforge.net/


----------

