|
Answer» Hello,
I have several file, 1KB each. Some are empty but few are not. If I merge all of them into one file I end up with blank lines. How can I find the empty files when I can not use the size and merge only the ones w/data? Or is there a way to remove the blank lines automatically from the NEW file?Test for the file size in a For loop using %%~zA and reject/accept the file for merging based on the file size using an If command. Note that if a file contains just a CR/LF it is not 'empty', the length will be shown as 2 bytes.
At the command prompt enter For /? to view For help
Post your script. Or exploit the fact that FOR /F skips blank lines
Code: [Select]if exist temp.txt del temp.txt for /f "delims=" %%a in (file.txt) do echo %%a >>temp.txt del file.txt ren temp.txt file.txt replace all INSTANCES of file.txt with NAME of file to remove blank lines fromThank you all for suggestions. I understand now why, even though the file 'looks' empty, it is not (size is 2 bytes). As a test, I combined 3 files (1 record each) into 1 and then removed the blank lines, at least I thought I did, but when I try to load them it shows 6 records where 3 are blank so the load process aborts. I don't think I can check for size because the file is only 2 bytes, as Dusty pointed out, it's not 'empty'.I can't get this to work. I still end up with 6 records when I only have 3. How I end up with 3 blank ones, which you can not actually see in the file, when I already removed the blank lines? Please, if anybody can help, let me know. Here are the batch files I am using.
rem RUN_CLEAN_TEST_FILE.BAT echo on date /t time /t call clean_test_file TEST1.txt TEST.txt exit
rem clean_test_file.bat echo off For /F "tokens=* delims=" %%A in (%1) Do Echo %%A >> %2 exit
Quote from: Cookie As a test, I combined 3 files (1 record each) into 1 and then removed the blank lines
How did you "combine" the files, which software did you use? Please post a screenshot of a hex editor output of test1.txt and test.txtHi, I don't use any software to combine the file, I just use the copy command because I want everything to run in batch: copy *.txt test1.txt /b Here is where test1.txt contains blanks so I run the clean batch to remove the blanks and create the test.txt file. I am not sure if this is what you're ASKING for, but here they are
[recovering disk space - old attachment deleted by admin]Suggest you do the lot in one script as below. This should READ your three test files and write them to output omitting blank lines, after testing you can change the inputs/output filenames to whatever you want:
Code: [Select]echo off cls
for /f "tokens=*" %%1 in (inputfile1.txt inputfile2.txt inputfile3.txt) do ( echo %%1>>outputfile.txt )
|