Announcement

Collapse
No announcement yet.

Compare two .txt-files but I would like to ignore the first two lines

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Compare two .txt-files but I would like to ignore the first two lines

    Hi!

    I'm working with test-automation and i'm using BC 4 in a scripted way in my testautomation-framework to compare print screens (.txt-files). But I would like to ignore the two first lines in every file when I do the comparison - file report. I have managed to do it in the BC GUI-editor but not when I run my scripts in the command-line.

    Can you help me with a solution for that?

    Best Regards,

    /luring

    Here is a sample of two script-files that I use:

    file-report layout:side-by-side &
    options:display-all,line-numbers &
    output-to:%3 output-options:html-color %1 %2

    file-report layout:side-by-side &
    options:ignore-unimportant,display-context &
    output-to:%3 output-options:html-color %1 %2

  • #2
    Hello,

    Starting in the graphical interface is the best first step. That it is working there but not script means we probably just need to verify that script is running as the same Windows User account, and that the settings you used in the graphical interface are set as the default behavior (which script can then use).

    First, if you load the files in the Text Compare, is the text unimportant without needing to click or alter any settings? If you do need to update any settings, such as manually switching file formats used, or unimportance, this behavior will need to be updated to be the default instead. To automatically pick the correct file format, update the format's file extension in the Tools menu -> File Formats dialog so that it is associated with your files. In the Session Settings tab, and uncheck the grammar element name, and update the bottom dropdown from "use only for this view" to "also update session defaults".

    Verify the files automatically compare as expected by closing and reloading BC4 with a new Text Compare file comaprison, then drag/drop your files into the new blank compare.

    Then, use the Windows Command line to manually call to your script with:
    bcompare.exe "@c:\bcscript.txt" "c:\file1" "c:\file2" "c:\bcreport.html"
    to verify the script works when called as the same Windows user from your desktop (to help troubleshoot if the automation itself is running as a different Windows user).

    If the User account is the issue, since each user has their own set of settings, you can update your automation to run as the same Windows User account, or install a Portable Install (which shares a common set of settings for any user running it) with the Setup.exe into a globally accessible folder such as C:\Tools\Beyond Compare 4\
    Aaron P Scooter Software

    Comment


    • #3
      When i restart BC and do the text compare again it doesn't work so I have to configure the settings again. Here is the File Format:

      Comment


      • #4
        I run BC with my own user. The setup.exe is in a globally accessible folder. Can you advice what to do?

        Comment


        • #5
          Hello,

          Is BC4 a portable install in a read-only directory? If you close and restart BC4 and all settings (sessions, etc) are gone, that means it is running from a read only location. Is BCState.xml within the install directory (next to BCompare.exe)? If yes, this is a Portable Install.

          Is this Portable Install in Program Files or Program Files (x86)? On modern Windows, this is a read-only location and you should not put a Portable Install here. You need to install to another location, such as C:\Tools\Beyond Compare 4\
          Aaron P Scooter Software

          Comment


          • #6
            Hi again!
            My installation is in this location: C:\Program Files\Beyond Compare 4.
            It is not a Portable install. The BCState.xml is not in the directory.
            The settings are not there when I restart BC4.
            What is the best solution for me?
            I also wonder if it is any easy way in scripted mode to se if the files is the same (a return code or something) when the second row with date and time are the only thing that differs?

            Regards,
            luring

            Comment


            • #7
              We're going to need a bit more specific information and list of steps to help troubleshoot the missing settings. Please try this:
              1) Launch BC4 and load a blank Folder Compare.
              2) Load two Desktop\test1\ and Desktop\test2\ folders to compare, with a couple sample files
              3) Use the Session menu -> Save Session, and give the session a custom name.
              4) Close BC4
              5) Relaunch BC4. Is the custom session saved in the saved sessions list?
              6) Reboot your computer. Is the custom session still saved in the sessions list?

              If it is a normal install in Program Files\, then the settings are part of your Windows User's %AppData%\ location, which is where many applications will store their per User settings.

              The easy solution is to use the interface to configure the default behavior (so the files default to that line being unimportant). You can then use BComp.com /qc "c:\file1" "c:\file2" to get a return code for if the files are equal, similar (only unimportant differences), or different. This requires the default behavior to already be configured in the graphical interface.
              Aaron P Scooter Software

              Comment


              • #8
                Answers:
                5) Yes.
                6) Yes.
                Now it suddenly works as I want.
                And I also get it to work with the scripting so it ignores the first two rows.
                How do I do to get a return code that I can use as a parameter to show that the files are the same/ or have unimportant differences that I don't have to look at? - Which are the different return codes and how do I script to get them and use them?

                I use this script to get:
                file-report layout:side-by-side &
                options:ignore-unimportant,display-context &
                output-to:%3 output-options:html-color %1 %2

                The result in html is like this:
                Text Compare
                Produced: 2019-05-08 07:45:38

                Mode: Differences, With Context, Ignoring Unimportant

                This is the command that I run in the commandline in my testautomation:
                C:\Program Files\Beyond Compare 4>BCompare.exe @GenerateReporthtml_ignore_unimportant.txt c:\folder1\file1_old.txt c:\folder2\file1_new.txt c:\Results\file1.html

                //luring

                Comment


                • #9
                  And actually it is only the second row that I would like to ignore. In fact jus the date and time on the second row (16 positions) that I would like to ignore.
                  Is that possible also?
                  /luring

                  Comment


                  • #10
                    Hello,

                    The return code for Scripting mode only returns if the script is successful or not. To return code for a comparison, it would be a separate run using /qc, and the return codes are documented in the Help file -> Command Line Reference chapter.

                    For ignoring only the second line, is there a Basic Grammar regular expression that would match on this line? The Lines grammar can match on line 1 or a reg ex, but there is no method to pick "line 2".
                    Aaron P Scooter Software

                    Comment


                    • #11
                      Hi again and thank you for your response!

                      How do you mean a separate run? After my comparison?
                      How is the syntax for that?
                      Can you give me an example?
                      How can i Catch the return code and use it / make a report/ or note in a report that theese files are the same?

                      /luring
                      Last edited by luring; 10-May-2019, 12:56 AM.

                      Comment


                      • #12
                        Yes, separate calls to Beyond Compare. Run the script first, then run the /qc command line.

                        Example:
                        bcompare.exe @c:\script.txt
                        bcompare.exe /qc file1.txt file2.txt

                        To output the error level returned by /qc in a batch file, use the command 'echo %errorlevel%'.
                        Chris K Scooter Software

                        Comment


                        • #13
                          I tried with this and I can't get it to work:
                          C:\Program Files\Beyond Compare 4>BCompare.exe @GenerateReporthtml_ignore_unimportant.txt T:\facit1\file1A.txt T:\new2\file1B.txt T:\Resultat\file1.html

                          C:\Program Files\Beyond Compare 4>BCompare.exe /qc T:\facit1\file1A.txt T:\new2\file1B

                          C:\Program Files\Beyond Compare 4>echo %errorlevel%
                          0

                          Was it like this you mean? It Always says 0 even if it is differences.
                          And how do i Catch and use the return code as an output so i can use it in the tool that runs the command line?

                          //luring

                          Comment


                          • #14
                            Hi again!

                            Also I have a problem with getting the ignore unimportant to work on Another computer. I have two computers and on the first one it works fine. But when I do the same on my other one it doesn't work. I followed the instructions and reboot and so on and it works fine in BC GUI but not the scripted way.

                            Do you have any idea about that? It is the same installation on this machine as it is on the one that works.

                            //luring

                            Comment


                            • #15
                              Hello,

                              For the echo error level, depending on your environment, you likely need to switch that command line to:
                              bcomp.com /qc T:\facit1\file1A.txt T:\new2\file1B
                              echo %ErrorLevel%

                              The .com is designed to run within a Command Line environment, and will better hold onto the error level for subsequent calls.

                              For swapping between computers, always double check the default graphical environment behavior. Load a new, blank Text View, load your two files into it, and verify that the default behavior is loading the correct File Format, and that the Session Settings are defaulting to the correct Importance values (unchecked in the Session menu -> Session Settings, Importance tab). When switching between computers, you need to remember to import both the File Format and the default Session Settings state.
                              Aaron P Scooter Software

                              Comment

                              Working...
                              X