Results 1 to 3 of 3

Thread: HELP - add new line in text file without format changed

  1. #1
    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

  2. #2
    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

  3. #3
    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

Similar Threads

  1. How to move to next line by PHP in text file?
    By Ramona19 in forum Software Development
    Replies: 4
    Last Post: 09-06-2011, 07:09 AM
  2. Replies: 4
    Last Post: 31-01-2011, 04:08 AM
  3. Assign each line of a text file to a variable
    By hitman126 in forum Operating Systems
    Replies: 1
    Last Post: 22-01-2011, 07:42 AM
  4. Replies: 19
    Last Post: 17-11-2010, 04:19 PM
  5. How to let Java read text file line by line.
    By Visala28 in forum Software Development
    Replies: 3
    Last Post: 04-08-2009, 11:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,957,042.29051 seconds with 17 queries