Solved Need Batch file to edit text.

July 17, 2012 at 08:53:43
Specs: Windows XP
I have 2000 metadata text files which are improperly formatted. I need to reformat it. here is an example of the data:
ImageWidth: 8160ImageLength: 10880BitsPerSample: 16
I need a batch file to make each piece of data one line.

See More: Need Batch file to edit text.

Report •

✔ Best Answer
July 18, 2012 at 07:05:41
I just noticed there is a typo in the code so use this one instead:

@echo off
for /f "tokens=*" %%i in ('dir /b /a-d *.txt') do (
for /f "tokens=1-3 delims=:ImageWidthLengthBitsPerSample" %%a in (
%%i
) do (
>_.tmp echo.ImageWidth:%%a
>>_.tmp echo.ImageLength:%%b
>>_.tmp echo.BitsPerSample:%%c
move _.tmp "%%i"
))

If you can, post one of the entire files to pastebin.com and then post the link here.

Tony



#1
July 17, 2012 at 10:52:20
Test this on a small subset of your files before running it against them all.

@echo off
for /f "tokens=*" %%i in ('dir /b /a-d *.txt') do (
for /f "tokens=1-3 delims=:ImageWidthLengthBitsPerSample" %%a in (
%%i
) do (
>_.tmp echo.ImageWidth:%%a
>>_.tmp echo.ImageLength:%%b
>>_.tmp echo.BitsPerSample:%%c
move _.tmp "%%%i"
))

Tony


Report •

#2
July 17, 2012 at 13:03:48
It did not work. I copied and pasted what you wrote into notepad, saved as a .bat, and moved my files onto it. Nothing happened. The black dos window just flashed and disappeared.

Report •

#3
July 17, 2012 at 17:40:27
Are your file extensions .txt? If not change the code to reflect the extension.Also make sure your files are in the same directory as the script, then double click the script.

Tony


Report •

Related Solutions

#4
July 18, 2012 at 06:12:18
Well, I tried that, but it took one file with hundreds of different metadata, and changed it to this:
ImageWidth:Co
ImageLength:y
BitsPerSample: Co
I understand that the code you gave was for only those three pieces of metadata, but it got rid of the numbers.

Report •

#5
July 18, 2012 at 06:40:41
I wonder if the line endings just aren't standard Windows line endings. If that's the problem, this should fix it.

How To Ask Questions The Smart Way


Report •

#6
July 18, 2012 at 07:05:41
✔ Best Answer
I just noticed there is a typo in the code so use this one instead:

@echo off
for /f "tokens=*" %%i in ('dir /b /a-d *.txt') do (
for /f "tokens=1-3 delims=:ImageWidthLengthBitsPerSample" %%a in (
%%i
) do (
>_.tmp echo.ImageWidth:%%a
>>_.tmp echo.ImageLength:%%b
>>_.tmp echo.BitsPerSample:%%c
move _.tmp "%%i"
))

If you can, post one of the entire files to pastebin.com and then post the link here.

Tony


Report •

#7
July 18, 2012 at 07:51:37
Nah, still didn't work Tony. Thanks for the help though. I don't think I can post one of the files because it is sensitive data. I will just do it manually.

Report •

#8
July 18, 2012 at 07:54:03
Can you post as much as you can? Now I am curious why it wasn't working because for me it was.

Edit: I see the problem, I didn't account for multiple lines in each file.
Tony


Report •

#9
July 18, 2012 at 08:25:45
NAH, see when I post it to pastebin it formats correctly, it only is bad in .txt format.

Report •

#10
July 18, 2012 at 08:26:45
Just to show you, I have to remove the spaces between the new lines to make it look like it does on my computer.
http://pastebin.com/DPzG4Cg7

Report •

#11
July 18, 2012 at 09:53:07
What is generating these files? Like Razor said it's probably an issue of non-Windows line endings.

Tony


Report •

#12
July 18, 2012 at 10:51:58
I am not sure, they were generated before I started work on them. All I know is it was very specific software from A lab in Texas. Like I said, I'll just do the reformatting myself. I can do about 2 a minute, so it shouldn't take too long. Thanks for all your help though.

Report •

Ask Question