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.
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
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
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.
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
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.
I wonder if the line endings just aren't standard Windows line endings. If that's the problem, this should fix it.
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
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.
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
NAH, see when I post it to pastebin it formats correctly, it only is bad in .txt format.
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
What is generating these files? Like Razor said it's probably an issue of non-Windows line endings. Tony
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.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |