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

Author Topic: Set a multiline variable in batch  (Read 47052 times)

0 Members and 1 Guest are viewing this topic.

_unknown_

    Topic Starter


    Beginner

    • Experience: Beginner
    • OS: Windows 7
    Re: Set a multiline variable in batch
    « Reply #15 on: January 28, 2016, 11:54:51 PM »
    Thanks, that's useful detail.

    But where does the multi-line data exist?  Is it inside a file?

    Do you want to put all the information that is inside one file, after line one of the other file?

    Yes foxidrive, the multi-line data is inside another file. And I want to put all the information from that file, after the line one of another file. Actually, I want to edit the extension name of my sample(but unable to modify it, sorry about that). The files are .vrt not .txt. VRT files are like xml files and the content per line has < and > character.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Set a multiline variable in batch
    « Reply #16 on: January 29, 2016, 01:33:18 PM »
    This might work:

    Code: [Select]
    @echo off
    for /f "usebackq delims=" %%a in ("file.vrt") do (
    echo(%%a
    if not defined stop type "file2.vrt"
    set stop=are-we-there-yet?
    )
    pause

    _unknown_

      Topic Starter


      Beginner

      • Experience: Beginner
      • OS: Windows 7
      Re: Set a multiline variable in batch
      « Reply #17 on: January 30, 2016, 01:27:05 AM »
      This might work:

      Code: [Select]
      if not defined stop type "file2.vrt"
      set stop=are-we-there-yet?

      Sorry to ask but what does this line means?

      _unknown_

        Topic Starter


        Beginner

        • Experience: Beginner
        • OS: Windows 7
        Re: Set a multiline variable in batch
        « Reply #18 on: January 30, 2016, 03:04:14 AM »
        This might work:

        Code: [Select]
        @echo off
        for /f "usebackq delims=" %%a in ("file.vrt") do (
        echo(%%a
        if not defined stop type "file2.vrt"
        set stop=are-we-there-yet?
        )
        pause

        How will i overwrite the output of this to the file.vrt? I have observed that when all the information from file2.vrt was inserted to file.vrt,, the 2nd line of the file.vrt was positioned right after the last character of the last line of file2.vrt when it should be on the line after the last line of file2.vrt.

        output in command line:

        Code: [Select]
        This is
           <Insert="Line 1">
             <Insert="Line 2">file1.vrt</Line2>
             <Insert="Line 2">1</Line2>
             <Insert="Line 3">file2.vrt</Line3>
             <Insert="Line 3">1</Line3>
             <Another line="Line 4">0</Line4>
           </Insert>  an
        example
        of
        input.txt

        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        Re: Set a multiline variable in batch
        « Reply #19 on: January 30, 2016, 03:55:28 AM »
        The reason it's butted up against the line above is the line endings, that I spoke to you about in your last thread on this same issue.

        In your file2.vrt there is no CR/LF pair at the end of the last line, and this is something that depends on the editor or process being used to create the file2.vrt file.

        Some files have that there, some don't.

        _unknown_

          Topic Starter


          Beginner

          • Experience: Beginner
          • OS: Windows 7
          Re: Set a multiline variable in batch
          « Reply #20 on: January 30, 2016, 05:28:44 AM »
          I see. Do you know how to overwrite the output to the file.vrt?

          I'm also wondering what this lines mean?

          Code: [Select]
          if not defined stop type "file2.vrt"
          set stop=are-we-there-yet?

          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Re: Set a multiline variable in batch
          « Reply #21 on: January 30, 2016, 09:50:20 AM »
          I forgot about redirecting it to a file.

          This also adds the missing CR/LF

          Code: [Select]
          @echo off
          (
          for /f "usebackq delims=" %%a in ("file.vrt") do (
          echo(%%a
          if not defined stop type "file2.vrt" &  echo(
          set stop=are-we-there-yet?
          ))>file.tmp
          move file.tmp "file.vrt" >nul
          pause

          Which part of the other two lines didn't you understand?

          _unknown_

            Topic Starter


            Beginner

            • Experience: Beginner
            • OS: Windows 7
            Re: Set a multiline variable in batch
            « Reply #22 on: January 30, 2016, 10:33:47 AM »
            I forgot about redirecting it to a file.

            This also adds the missing CR/LF

            Code: [Select]
            @echo off
            (
            for /f "usebackq delims=" %%a in ("file.vrt") do (
            echo(%%a
            if not defined stop type "file2.vrt" &  echo(
            set stop=are-we-there-yet?
            ))>file.tmp
            move file.tmp "file.vrt" >nul
            pause

            Which part of the other two lines didn't you understand?

            I don't understand the two lines  :(  Is this only possible with one file? or is it also possible with many files?like I have many file.vrt in a folder and I want to insert file2.vrt in all of them. I also want  to add the directory of where the file2.vrt is located.
            This is what I did, but no luck  :(
            Code: [Select]
            @echo off

            set "input=C:\path\to\files\"
            set "output=C:\path\to\output\"
            set "file2=C:\path\to\file2\"

            cd /d "%in_path%"
            for /f "usebackq delims=" %%a in (*.file.vrt) do (
            set "fileName=%%a
            echo(%%a
            if not defined stop type "%file2%\file2.vrt"
            set stop=are-we-there-yet?

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: Set a multiline variable in batch
            « Reply #23 on: January 30, 2016, 11:15:04 AM »
            I don't understand the two lines  :(  Is this only possible with one file? or is it also possible with many files?

            Yes, more files are possible.
            But it needs changed code. 

            if you provide accurate details in the beginning then you don't waste the time of the volunteers, and you get a working script in the first reply.

            Geek-9pm


              Mastermind
            • Geek After Dark
            • Thanked: 1026
              • Gekk9pm bnlog
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Re: Set a multiline variable in batch
            « Reply #24 on: January 30, 2016, 11:27:39 AM »
            For what it's worth..
            The general method of overwriting a file after a join operation.
              Open three files, two input, one output.
              Perform the join on the two input files.
              Send output to the third file.
              If job is free of error, then
                rename the original file as a backup.
                rename the output file to the original name.
             else report error
            end of job.

            Trying to overwrite the original file "on the wing" is a very bad idea.


            _unknown_

              Topic Starter


              Beginner

              • Experience: Beginner
              • OS: Windows 7
              Re: Set a multiline variable in batch
              « Reply #25 on: January 30, 2016, 11:41:14 AM »
              Yes, more files are possible.
              But it needs changed code. 

              if you provide accurate details in the beginning then you don't waste the time of the volunteers, and you get a working script in the first reply.

              I'm sorry I forgot about that. That is the last thing I need.

              _unknown_

                Topic Starter


                Beginner

                • Experience: Beginner
                • OS: Windows 7
                Re: Set a multiline variable in batch
                « Reply #26 on: January 31, 2016, 12:20:29 AM »
                Yes, more files are possible.
                But it needs changed code. 

                if you provide accurate details in the beginning then you don't waste the time of the volunteers, and you get a working script in the first reply.


                I hope you can still help me about it  :(

                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: Set a multiline variable in batch
                « Reply #27 on: January 31, 2016, 05:56:08 AM »
                You've still hidden most aspects in your new thread, and posted it elsewhere too.

                I dislike writing code when it's all made up - what happens is what you've already seen, the volunteer has to re-write the code again.

                If the question is simple and no effort is needed then I'll offer a suggestion - but if it's complex then more work is needed to give a solution, and in the same way even more work is needed to re-write *that* script when some other aspect turns out to be important, and was hidden.

                It may not seem such a horrible thing - but when it's happened for the ten thousandth time, it gets a bit irritating. :D

                _unknown_

                  Topic Starter


                  Beginner

                  • Experience: Beginner
                  • OS: Windows 7
                  Re: Set a multiline variable in batch
                  « Reply #28 on: January 31, 2016, 06:21:30 AM »
                  That's the last thing I need in this topic. i just had numerous files and forgot to include it.
                  I don't know how to solve it even when I tried and tried. Just asking for help since it's an urgent matter. I apologize.

                  _unknown_

                    Topic Starter


                    Beginner

                    • Experience: Beginner
                    • OS: Windows 7
                    Re: Set a multiline variable in batch
                    « Reply #29 on: February 01, 2016, 12:23:47 AM »
                    After trying and trying I've come up with this code:

                    Code: [Select]
                    @echo off

                    set src=C:\path\to\source\files
                    set dst=C:\path\to\destination\files

                    for /f "tokens=*" %%a in ('dir /b "%src%\*.file.vrt"') do (
                       for /f "usebackq delims=" %%h in ("%%a") do (
                       echo(%%h
                       if not defined stop type "%src%\file2.vrt"
                       set stop=are-we-there-yet?
                       ))>%dst%\%%~na.tmp
                       move /y %dst%\%%~na.txt %dst%\%%~na.vrt >nul
                    )

                    But after running this code, the output files from the dst folder looks likes this: (It happens to all the files I have in src folder)
                    Can't figure out what is causing this error and how to fix it.

                    Code: [Select]
                    C:\path\to\destination\files>(
                    echo(<This is line 1 of file.vrt> 
                     if not defined stop type "file2.vrt" 
                     set stop=are-we-there-yet?
                    )
                    <This is line 1 of file.vrt>
                       <Insert="Line 1">
                         <Insert="Line 2">file1.vrt</Line2>
                         <Insert="Line 2">1</Line2>
                         <Insert="Line 3">file2.vrt</Line3>
                         <Insert="Line 3">1</Line3>
                         <Another line="Line 4">0</Line4>
                       </Insert>
                    C:\path\to\destination\files>(
                    echo(  This is line 2 of file.vrt
                     if not defined stop type "file2.vrt" 
                     set stop=are-we-there-yet?
                    )
                      This is line 2 of file.vrt

                    C:\path\to\destination\files>(
                    echo(  <This is line 3 of file.vrt> 
                     if not defined stop type "file2.vrt" 
                     set stop=are-we-there-yet?
                    )
                      <This is line 3 of file.vrt>

                    C:\path\to\destination\files>(
                    echo(    <This is line 4 of file.vrt> 
                     if not defined stop type "file2.vrt" 
                     set stop=are-we-there-yet?
                    )
                        <This is line 4 of file.vrt>

                    and so on. . . . . . . .

                    This error also appears at the end of the line:

                    Code: [Select]
                    C:\path\to\destination\files>move /y C:\path\to\destination\files\
                    %~na.txt C:\path\to\destination\files\%~na.vrt  1>nul
                    The system cannot find the file specified.
                    « Last Edit: February 01, 2016, 12:55:00 AM by _unknown_ »