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

Author Topic: how to change text line 1 without delete other text  (Read 6302 times)

0 Members and 1 Guest are viewing this topic.

kanifusa

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 10
    how to change text line 1 without delete other text
    « on: November 28, 2019, 01:22:33 AM »
    example c:\account.txt

    inside text is

    Account1 : 88888888
    Account2 : 11326665
    Account3 : 11553625

    how to use "bat or cmd"  change line1 text without delete other line text
    can i change
    Account1 : 88888888 to Account1 : 9999999

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: how to change text line 1 without delete other text
    « Reply #1 on: November 28, 2019, 10:54:56 AM »
    Normally one would just use Notepad.
    However, if you need to do it with a bat program, you will have to use a tool that is not included in Windows.
    You can get a program used in Linux. There is a windows version of SED.
    https://www.computerhope.com/unix/used.htm
    Quote
    sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file, or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
    Here is the Windows version:
    https://www.computerhope.com/forum/index.php?topic=163602.0
    http://gnuwin32.sourceforge.net/packages/sed.htm
    Does this help?

    kanifusa

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Windows 10
      Re: how to change text line 1 without delete other text
      « Reply #2 on: November 28, 2019, 11:32:39 AM »
      @echo off &setlocal DisableDelayedExpansion
      set "file=account.txt"
      set "fristline=Account1 : 9999999"

      setlocal EnableDelayedExpansion
      <"!file!" >"!file!.tmp~" (
        for /f %%i in ('type "!file!"^|find /v /c  ""') do for /l %%j in (2 1 %%i) do (
          set "line=" &set /p "line="
          echo(!line!
        )
      )
      >>"!file!.tmp~" echo(!fristline!
      move /y "!file!.tmp~" "!file!"

      how to make this replace Account1 : 9999999 to frist line not last line