Remove New line Char from Text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove New line Char from Text file

#16 Post by foxidrive » 20 Nov 2012 23:50

You need to double all the \ characters to \\

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove New line Char from Text file

#17 Post by foxidrive » 20 Nov 2012 23:53

Try this:

Code: Select all

@set @JScript=1/*
@echo off
setlocal

cscript //nologo //E:JScript "%~f0"
goto :eof

*/

// JScript
//
var ForReading= 1
var ForWriting = 2

var fso = new ActiveXObject("Scripting.FileSystemObject");
// var input = fso.OpenTextFile("c:\\temp\\webconfig.txt", ForReading)
// var output = fso.OpenTextFile("c:\\temp\\newWebConfig.xml", ForWriting, true)

var input = fso.OpenTextFile("Z:\\STG_URS\\1\\115A_CONTRACT_EXPER", ForReading)
var output = fso.OpenTextFile("Z:\\STG_URS\\1\\newfile", ForWriting, true)


var data = input.Readall()
data = data.replace(/\x0A/gi, "")
data = data.replace(/\x0D/gi, "\x0D\x0A")

output.Write(data)

input.Close()
output.Close()

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Remove New line Char from Text file

#18 Post by aaksar » 21 Nov 2012 02:22

Thanks a Ton FoxDrive.

Its working fine...

another thing that i need to achive. if you can help me out, i m new in batch script.

i need to pole the FTP location , and move the file to my Informatica location, unzip the file (8 files coming as zip rest of files are unzipped).
every 5 mins it will wakeup and check the file, everytime check in my informatica dir whether it reached the count of files like (assume i need to receive 15 files) so if its 15 then create a 0 byte file and stop polling.

Thanks in advance

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove New line Char from Text file

#19 Post by foxidrive » 21 Nov 2012 03:06

Start another thread for a new topic.

Provide all the details of the task, like the batch files you are using.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Remove New line Char from Text file

#20 Post by aaksar » 21 Nov 2012 06:51

Thanks a Ton :)

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Remove New line Char from Text file

#21 Post by aaksar » 21 Nov 2012 07:02

How can i use this script for multiple file, like i have 15 files (can be increase)
can make it like it read all the files from folder and create new files without special char and then remove all the special char file.

sorry , i hv no idea how to achive this

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove New line Char from Text file

#22 Post by foxidrive » 21 Nov 2012 07:14

Just a tip - when you ask for help with a task then make the description complete, so you don't ask for more things once you have a solution.
Often the solution changes a lot with just a small difference in the request.


So use the two batch files below. Name the top one "removechar1.bat" and name the bottom one "removechar2.bat"
Put them both in the same folder.

Change e:\folder\ in the top batch file to where your 15 or more files are, and make sure there are no other files in that folder.

Then run "removechar1.bat" and it should process all the files. Make sure you test it on sample files first.


Code: Select all

@echo off
for %%a in ("E:\folder\*") do (
copy /y "%%a" infile.tmp >nul
call "removechar2.bat"
move /y outfile.tmp "%%a"
del infile.tmp
)


Code: Select all

@set @JScript=1/*
@echo off
setlocal

cscript //nologo //E:JScript "%~f0"
goto :eof

*/

// JScript
//
var ForReading= 1
var ForWriting = 2

var fso = new ActiveXObject("Scripting.FileSystemObject");
// var input = fso.OpenTextFile("c:\\temp\\webconfig.txt", ForReading)
// var output = fso.OpenTextFile("c:\\temp\\newWebConfig.xml", ForWriting, true)
var input = fso.OpenTextFile("infile.tmp", ForReading)
var output = fso.OpenTextFile("outfile.tmp", ForWriting, true)


var data = input.Readall()
data = data.replace(/\x0A/gi, "")
data = data.replace(/\x0D/gi, "\x0D\x0A")

output.Write(data)

input.Close()
output.Close()

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Remove New line Char from Text file

#23 Post by aaksar » 22 Nov 2012 01:34

Foxdrive Thanks for your great help. its perfectly working...

i have initated new thread for FTP problem, pls look into it.

Thanks in Advance

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove New line Char from Text file

#24 Post by foxidrive » 22 Nov 2012 01:40

Scripts involving FTP aren't fun. Maybe someone else will take it up.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Remove New line Char from Text file

#25 Post by aaksar » 12 Mar 2013 04:56

Hi when i am running this script is giving me error " out of memory"

any resolution for this " file size is 800 mb

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove New line Char from Text file

#26 Post by foxidrive » 12 Mar 2013 05:15

Increase your RAM or virtual memory, or close other programs when it runs.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Remove New line Char from Text file

#27 Post by Squashman » 12 Mar 2013 05:45

foxidrive wrote:Increase your RAM or virtual memory, or close other programs when it runs.

Yep. I used to run into that issue all the time on my old XP computer that only had 1GB of ram. I pretty much new that I couldn't work with files much larger than about 650MB because of all the memory the system was using and all the other apps I was running to do my job.

My new computer at work only has 4GB of ram. I so hate it when companies go cheap on ram. I just built a new computer for my own home use and threw 16GB of ram and it was very inexpensive.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove New line Char from Text file

#28 Post by foxidrive » 12 Mar 2013 05:49

I still use 32 bit Windows so am limited to 3.5 GB ram in Windows 8.
But it serves me well still.

if I had 64 bit then I'd also splash out on 16 GB!

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Remove New line Char from Text file

#29 Post by aaksar » 12 Mar 2013 10:59

I have 32 GB RAM on my server and still getting the same error., dont know why.

it was working fine on 200 mb file.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Remove New line Char from Text file

#30 Post by aaksar » 12 Mar 2013 11:01

and 1 more thing.... while giving error" out of memory" its making my data file 0 byte....

Post Reply