How to output a line containing a match AND the line before?












-3
















Tool zur Imageverwaltung für die Bereitstellung

Version: 10.0.17763.1

Abbildversion: 10.0.17763.253

Funktionsliste:

Funktionsidentität : Browser.InternetExplorer~~~~0.0.11.0

Status : Nicht vorhanden

Funktionsidentität : Hello.Face.17658~~~~0.0.1.0

Status : Installiert

Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0

Status : Installiert

Funktionsidentität : Language.Basic~~~af-ZA~0.0.1.0

Status : Nicht vorhanden




I want to output the lines where the next line contains Status: Installiert.



I know how to find the lines containing the string Installiert, but don't know how to include the whole line before the match.










share|improve this question





























    -3
















    Tool zur Imageverwaltung für die Bereitstellung

    Version: 10.0.17763.1

    Abbildversion: 10.0.17763.253

    Funktionsliste:

    Funktionsidentität : Browser.InternetExplorer~~~~0.0.11.0

    Status : Nicht vorhanden

    Funktionsidentität : Hello.Face.17658~~~~0.0.1.0

    Status : Installiert

    Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0

    Status : Installiert

    Funktionsidentität : Language.Basic~~~af-ZA~0.0.1.0

    Status : Nicht vorhanden




    I want to output the lines where the next line contains Status: Installiert.



    I know how to find the lines containing the string Installiert, but don't know how to include the whole line before the match.










    share|improve this question



























      -3












      -3








      -3


      1







      Tool zur Imageverwaltung für die Bereitstellung

      Version: 10.0.17763.1

      Abbildversion: 10.0.17763.253

      Funktionsliste:

      Funktionsidentität : Browser.InternetExplorer~~~~0.0.11.0

      Status : Nicht vorhanden

      Funktionsidentität : Hello.Face.17658~~~~0.0.1.0

      Status : Installiert

      Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0

      Status : Installiert

      Funktionsidentität : Language.Basic~~~af-ZA~0.0.1.0

      Status : Nicht vorhanden




      I want to output the lines where the next line contains Status: Installiert.



      I know how to find the lines containing the string Installiert, but don't know how to include the whole line before the match.










      share|improve this question

















      Tool zur Imageverwaltung für die Bereitstellung

      Version: 10.0.17763.1

      Abbildversion: 10.0.17763.253

      Funktionsliste:

      Funktionsidentität : Browser.InternetExplorer~~~~0.0.11.0

      Status : Nicht vorhanden

      Funktionsidentität : Hello.Face.17658~~~~0.0.1.0

      Status : Installiert

      Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0

      Status : Installiert

      Funktionsidentität : Language.Basic~~~af-ZA~0.0.1.0

      Status : Nicht vorhanden




      I want to output the lines where the next line contains Status: Installiert.



      I know how to find the lines containing the string Installiert, but don't know how to include the whole line before the match.







      windows cmd






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 20 at 15:21









      Mofi

      28.4k83777




      28.4k83777










      asked Jan 20 at 15:03









      DerBaronTVDerBaronTV

      12




      12
























          1 Answer
          1






          active

          oldest

          votes


















          1














          This command line written into a batch file can be used for this task:



          @for /F "usebackq delims= eol=" %%I in ("TextFile.txt") do @for /F "tokens=2 eol= delims=: " %%J in ("%%~I") do @if "%%~J" == "Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR interprets " as end of line character. So lines starting with " would be ignored by outer FOR.



          The inner FOR interprets a space character as end of line character which does not matter here because the space character is also a delimiter. The line splitting is done first by FOR resulting in removing all spaces and colons from beginning of line and so space as end of line character is no problem here.



          Thanks goes to aschipfl for these additional information on how the two FOR above with the specified options process the lines in specified text file.



          Better would be:



          @for /F usebackq^ delims^=^ eol^= %%I in ("TextFile.txt") do @for /F "tokens=2 delims=: eol=" %%J in ("%%~I") do @if "%%~J" == " Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR is run with an empty list of string delimiters and no end of line character. The inner FOR is run also with no end of line character, but with just colon as string delimiter which is the reason for the space character at beginning of the string to compare.



          Both command lines output on execution with file TextFile.txt in current directory containing the posted lines:



          Funktionsidentität : Hello.Face.17658~~~~0.0.1.0
          Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0


          For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




          • call /?

          • echo /?

          • for /?

          • if /?

          • set /?






          share|improve this answer


























          • This would define a " as the eol character for the outer for /F loop and a space for the inner one (although for the latter it is no problem as the space is also a delimiter, which has got a higher priority)...

            – aschipfl
            Jan 23 at 9:29













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54277730%2fhow-to-output-a-line-containing-a-match-and-the-line-before%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          This command line written into a batch file can be used for this task:



          @for /F "usebackq delims= eol=" %%I in ("TextFile.txt") do @for /F "tokens=2 eol= delims=: " %%J in ("%%~I") do @if "%%~J" == "Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR interprets " as end of line character. So lines starting with " would be ignored by outer FOR.



          The inner FOR interprets a space character as end of line character which does not matter here because the space character is also a delimiter. The line splitting is done first by FOR resulting in removing all spaces and colons from beginning of line and so space as end of line character is no problem here.



          Thanks goes to aschipfl for these additional information on how the two FOR above with the specified options process the lines in specified text file.



          Better would be:



          @for /F usebackq^ delims^=^ eol^= %%I in ("TextFile.txt") do @for /F "tokens=2 delims=: eol=" %%J in ("%%~I") do @if "%%~J" == " Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR is run with an empty list of string delimiters and no end of line character. The inner FOR is run also with no end of line character, but with just colon as string delimiter which is the reason for the space character at beginning of the string to compare.



          Both command lines output on execution with file TextFile.txt in current directory containing the posted lines:



          Funktionsidentität : Hello.Face.17658~~~~0.0.1.0
          Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0


          For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




          • call /?

          • echo /?

          • for /?

          • if /?

          • set /?






          share|improve this answer


























          • This would define a " as the eol character for the outer for /F loop and a space for the inner one (although for the latter it is no problem as the space is also a delimiter, which has got a higher priority)...

            – aschipfl
            Jan 23 at 9:29


















          1














          This command line written into a batch file can be used for this task:



          @for /F "usebackq delims= eol=" %%I in ("TextFile.txt") do @for /F "tokens=2 eol= delims=: " %%J in ("%%~I") do @if "%%~J" == "Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR interprets " as end of line character. So lines starting with " would be ignored by outer FOR.



          The inner FOR interprets a space character as end of line character which does not matter here because the space character is also a delimiter. The line splitting is done first by FOR resulting in removing all spaces and colons from beginning of line and so space as end of line character is no problem here.



          Thanks goes to aschipfl for these additional information on how the two FOR above with the specified options process the lines in specified text file.



          Better would be:



          @for /F usebackq^ delims^=^ eol^= %%I in ("TextFile.txt") do @for /F "tokens=2 delims=: eol=" %%J in ("%%~I") do @if "%%~J" == " Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR is run with an empty list of string delimiters and no end of line character. The inner FOR is run also with no end of line character, but with just colon as string delimiter which is the reason for the space character at beginning of the string to compare.



          Both command lines output on execution with file TextFile.txt in current directory containing the posted lines:



          Funktionsidentität : Hello.Face.17658~~~~0.0.1.0
          Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0


          For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




          • call /?

          • echo /?

          • for /?

          • if /?

          • set /?






          share|improve this answer


























          • This would define a " as the eol character for the outer for /F loop and a space for the inner one (although for the latter it is no problem as the space is also a delimiter, which has got a higher priority)...

            – aschipfl
            Jan 23 at 9:29
















          1












          1








          1







          This command line written into a batch file can be used for this task:



          @for /F "usebackq delims= eol=" %%I in ("TextFile.txt") do @for /F "tokens=2 eol= delims=: " %%J in ("%%~I") do @if "%%~J" == "Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR interprets " as end of line character. So lines starting with " would be ignored by outer FOR.



          The inner FOR interprets a space character as end of line character which does not matter here because the space character is also a delimiter. The line splitting is done first by FOR resulting in removing all spaces and colons from beginning of line and so space as end of line character is no problem here.



          Thanks goes to aschipfl for these additional information on how the two FOR above with the specified options process the lines in specified text file.



          Better would be:



          @for /F usebackq^ delims^=^ eol^= %%I in ("TextFile.txt") do @for /F "tokens=2 delims=: eol=" %%J in ("%%~I") do @if "%%~J" == " Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR is run with an empty list of string delimiters and no end of line character. The inner FOR is run also with no end of line character, but with just colon as string delimiter which is the reason for the space character at beginning of the string to compare.



          Both command lines output on execution with file TextFile.txt in current directory containing the posted lines:



          Funktionsidentität : Hello.Face.17658~~~~0.0.1.0
          Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0


          For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




          • call /?

          • echo /?

          • for /?

          • if /?

          • set /?






          share|improve this answer















          This command line written into a batch file can be used for this task:



          @for /F "usebackq delims= eol=" %%I in ("TextFile.txt") do @for /F "tokens=2 eol= delims=: " %%J in ("%%~I") do @if "%%~J" == "Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR interprets " as end of line character. So lines starting with " would be ignored by outer FOR.



          The inner FOR interprets a space character as end of line character which does not matter here because the space character is also a delimiter. The line splitting is done first by FOR resulting in removing all spaces and colons from beginning of line and so space as end of line character is no problem here.



          Thanks goes to aschipfl for these additional information on how the two FOR above with the specified options process the lines in specified text file.



          Better would be:



          @for /F usebackq^ delims^=^ eol^= %%I in ("TextFile.txt") do @for /F "tokens=2 delims=: eol=" %%J in ("%%~I") do @if "%%~J" == " Installiert" (call echo(%%Line%%) else set "Line=%%I"


          The outer FOR is run with an empty list of string delimiters and no end of line character. The inner FOR is run also with no end of line character, but with just colon as string delimiter which is the reason for the space character at beginning of the string to compare.



          Both command lines output on execution with file TextFile.txt in current directory containing the posted lines:



          Funktionsidentität : Hello.Face.17658~~~~0.0.1.0
          Funktionsidentität : Hello.Face.Migration.17658~~~~0.0.1.0


          For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.




          • call /?

          • echo /?

          • for /?

          • if /?

          • set /?







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 23 at 10:09

























          answered Jan 20 at 15:41









          MofiMofi

          28.4k83777




          28.4k83777













          • This would define a " as the eol character for the outer for /F loop and a space for the inner one (although for the latter it is no problem as the space is also a delimiter, which has got a higher priority)...

            – aschipfl
            Jan 23 at 9:29





















          • This would define a " as the eol character for the outer for /F loop and a space for the inner one (although for the latter it is no problem as the space is also a delimiter, which has got a higher priority)...

            – aschipfl
            Jan 23 at 9:29



















          This would define a " as the eol character for the outer for /F loop and a space for the inner one (although for the latter it is no problem as the space is also a delimiter, which has got a higher priority)...

          – aschipfl
          Jan 23 at 9:29







          This would define a " as the eol character for the outer for /F loop and a space for the inner one (although for the latter it is no problem as the space is also a delimiter, which has got a higher priority)...

          – aschipfl
          Jan 23 at 9:29






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54277730%2fhow-to-output-a-line-containing-a-match-and-the-line-before%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Homophylophilia

          Updating UILabel text programmatically using a function

          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage