Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Use batch file to insert text in a text file after a word i specify?  (Read 36999 times)

0 Members and 1 Guest are viewing this topic.

devcom



    Apprentice

    Thanked: 37
    Re: Use batch file to insert text in a text file after a word i specify?
    « Reply #15 on: April 24, 2009, 08:19:58 AM »
    i dont know...

    Code: [Select]
    @ECHO OFF
    set SrcFolder=c:\test
    set DstFolder=C:\test1

    for %%a in ("%SrcFolder%\*.txt") do (

      for /f "usebackq delims=" %%h in ("%%a") do (
        if "%%h" equ "SYS CONFIG 20090327" (echo SYS CONFIG 20090427) else (echo.%%h)
      ) >"%DstFolder%\%%~nxa"
     
    )

    ECHO.
    ECHO Done!
    ECHO.
    PAUSE
    CLS
    Download: Choice.exe

    rytech

      Topic Starter


      Rookie

      Re: Use batch file to insert text in a text file after a word i specify?
      « Reply #16 on: April 24, 2009, 09:08:36 AM »
      still saying the system cannot find the path specified mate any ideas?

      devcom



        Apprentice

        Thanked: 37
        Re: Use batch file to insert text in a text file after a word i specify?
        « Reply #17 on: April 24, 2009, 12:13:04 PM »
        Code: [Select]
        for %%a in ("%SrcFolder%\*.txt") do (to
        Code: [Select]
        for /f "tokens=*" %%a in ('dir /b "%SrcFolder%\*.txt"') do (
        and are you sure there are .txt files in c:\test ??
        Download: Choice.exe

        Aegis



          Expert

          Thanked: 67
          • Yes
          • Yes
          • Brian's Mess Of A Web Page
        • Experience: Experienced
        • OS: Windows 10
        Re: Use batch file to insert text in a text file after a word i specify?
        « Reply #18 on: April 24, 2009, 12:47:26 PM »
        Quote
        but i cant express how greatful i am to you all


        You may express your gratitude by sending money to me.

        I am the unofficial project manager.  I am here to do none of the work, but claim all the credit, and reap the rewards!  ;)   ::) 


        "For you, a thousand times over." - "The Kite Runner"

        ram



          Newbie

          • Experience: Beginner
          • OS: Windows 7
          Re: Use batch file to insert text in a text file after a word i specify?
          « Reply #19 on: April 24, 2017, 08:44:10 PM »
          Hi everyone,
          Thanks for this post it helped me a lot in doing my project but i am facing some issue,hope you can suggest me how to get out of this...

          As part of a project I need to add text to the middle of many files using batch scripting. I am able to add the text successfully, but after copying the files to a new location I noticed that the HTML tags are missing. I only have this problem in Windows Server 2012/2008; in Windows 7 the HTML tags remain.

          My Code snippet:
          @echo off

          set SrcFolder=C:\Users\emlfilessample
          set DstFolder=C:\Users\output

          FOR %%f in (%SrcFolder%*.eml) do (
           (FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ %%f"`) do (
            SETLOCAL EnabledDelayedExpansion
            set "var=%%a"
             set "var=!var:*:=!"
             if "!var:~0,10" == "x-globalre" (
             echo X-SUBTYPE=RETURES
           )
           echo(!var!
           ENDLOCAL
          )) >> "%DstFolder%\%%~nxf"
          )


           **Sample input eml:**
             Date Mon,20 mar 2017
             From:[email protected]
             To:[email protected]
             Message-ID:<10091223>
              Subject:Symphony
             x-globalrelay-MsgType: XXXX
             x-StreamType:xxxx
             x-contentstartdate:XXX
           
             <html><body>  Message ID:sm9atRNTnMA=Yay1R0QgoH.............. </html>

          After executing my script in Server 2012 I am able to successfully inject the required text in the middle, but as I said the HTML tags are missing:

           **Sample output eml:**
             Date Mon,20 mar 2017
             From:[email protected]
             To:[email protected]
             Message-ID:<10091223>
              Subject:Symphony
             echo X-SUBTYPE=RETURES
             x-globalrelay-MsgType: XXXX
             x-StreamType:xxxx
             x-contentstartdate:XXX
           
             < Yay1R0QgoH.............. </html>
           as shown above after executing the script the html tags at the begining are missing i am not able to find out why....can any one help me with this