Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-09-2011
Member
 
Join Date: Sep 2011
Posts: 2
HELP - add new line in text file without format changed

i get the script from other forum. but im still have problem with the format after processing.

this is my script.
@ECHO OFF
SET origfile="C:\Documents and Settings\user\Desktop\test1\before.txt"
SET tempfile="C:\Documents and Settings\user\Desktop\test1\after.txt"
SET insertbefore=4
FOR /F %%C IN ('FIND /C /V "" ^<%origfile%') DO SET totallines=%%C

<%origfile% (FOR /L %%i IN (1,1,%totallines%) DO (
SETLOCAL EnableDelayedExpansion
SET /P L=
IF %%i==%insertbefore% ECHO(
ECHO(!L!
ENDLOCAL
)
) >%tempfile%
COPY /Y %tempfile% %origfile% >NUL
DEL %tempfile%
pause

this script i save as run1.bat. after running, the format is out of order

original file
header 1<--here got tab delimited format--><--here got tab delimited format-->
header 2<--here got tab delimited format--><--here got tab delimited format-->
header 3<--here got tab delimited format--><--here got tab delimited format-->
details 1
details 2

output:
header 1<--tab delimited is missing--><--tab delimited is missing-->
header 2<--tab delimited is missing--><--tab delimited is missing-->
header 3<--tab delimited is missing--><--tab delimited is missing-->

details 1
details 2
Reply With Quote
  #2  
Old 13-09-2011
Member
 
Join Date: Jan 2006
Posts: 605
Re: HELP - add new line in text file without format changed

Maybe something like below can help you sort out the problem:

Code:
@echo OFF

:: Get the number of lines in the file
set LINES=0
for /f "delims==" %%I in (data.txt) do (
    set /a LINES=LINES+1
)

:: Print the last 10 lines (suggestion to use more courtsey of dmityugov)
set /a LINES=LINES-10
more +%LINES% < data.txt
Reply With Quote
  #3  
Old 13-09-2011
Member
 
Join Date: Sep 2011
Posts: 2
Re: HELP - add new line in text file without format changed

where to i put this code under mine script? please advise
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "HELP - add new line in text file without format changed"
Thread Thread Starter Forum Replies Last Post
How to move to next line by PHP in text file? Ramona19 Software Development 4 09-06-2011 07:09 AM
XP/Energy Rate changed and Boss fight format changed in Mafia Wars Zathara Video Games 4 31-01-2011 04:08 AM
Assign each line of a text file to a variable hitman126 Operating Systems 1 22-01-2011 07:42 AM
script to extract data from text file and put into excel format tdubb Windows Server Help 19 17-11-2010 04:19 PM
How to let Java read text file line by line. Visala28 Software Development 3 04-08-2009 11:30 PM


All times are GMT +5.5. The time now is 09:21 PM.