Home > Back-end >  How to Remove the empty row in a txt file with batch
How to Remove the empty row in a txt file with batch

Time:01-11

Need a bit of help with this and I do understand that with batch a empty row gets added to the end of the txt file

But I need to temporarily remove that so my next script can work

I have tried 3 different ways to make this work and can't figure it out

This is my script

@echo off

FOR %%i IN ("Toedit\Ready.txt") do (
findstr /V "^$" "%%i" >> "%%i.tmp"
    >>"%%i.tmp" echo  ,
    del "%%i"
    ren "%%i.tmp" "%%~nxi"
)

I have also tried doing this

for /f "usebackq tokens=* delims=" %%a in ("Ready.txt") do (echo(%%a)>>~.txt
move /y  ~.txt "Ready.txt"

But the end result is the same

Here is my Ready.txt file content

"dfhg": [
   1,
   2,
   10,
   4,
   8,
   9,
   3,
   6,
   7,
   5
empty space

My Bad Results

"dfhg": [
   1,
   2,
   10,
   4,
   8,
   9,
   3,
   6,
   7,
   5
,
empty space

My Final Results

"dfhg": [
   1,
   2,
   10,
   4,
   8,
   9,
   3,
   6,
   7,
   5,
empty space

I understand that batch creates an empty space and I'm ok with that, but I really need it removed so I can add the ,

CodePudding user response:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
rem The following settings for the directories and filenames are names
rem that I use for testing and deliberately includes spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.

SET "sourcedir=u:\your files"
SET "destdir=u:\your results"
SET "filename1=%sourcedir%\q75073481.txt"
SET "outfile=           
  • Related