Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Showing posts with label File Comparision. Show all posts
Showing posts with label File Comparision. Show all posts

How to create and run a batch file

Batch files help user to execute a set of command to be executed in the defined order by  executing a batch file. We can execute large number of commands in one go using bat file.

Creating a batch file


A batch file has extension .bat .To create a new bat file, we can save a file in text editor like notepad in format .bat.

Some useful batch commands


@echo off – this will not echo the text post the command and will show only the execution result in the command prompt.

@echo on – this will echo the text post the command and will show the command as well as the execution result in the command prompt.

Pause If we use pause, the batch file execution is halted until further intervention of user by pressing keys.

Arguments %1,%2,….. – This gives the parameter for the batch file.

echo val will display val in the command prompt

:: and rem can be used to add remarks to the script

Cls can be used to clear the command prompt


Example :

For e.g we need to compare 2 txt files, but name of files to be compared needs to be passed dynamically and log path also needs to be defined dynamically.

The content of batch file for this will look like

@echo off

Fc %1 %2 /n>%3

Pause

To execute this bat file, we have to write in run as

D:\Sample\new.bat d:\Sample\test4.txt d:\Sample\test7.txt d:\Sample\test9.txt


How to create and run a batch file



How to compare content of files using fc command

I was having issues with comparison of two large csv files that I came across fc comparision command of Microsoft DOS. fc  is a command line program that compares multiple files and outputs the differences between them


The syntax of fc Command and results of execution of fc with different arguments is shown below:




Syntax for fc command:


fc filename1 filename 2 [Parameter for comparision type] >Log File Path

where filename1 and filename2 are paths of the two files to be compared .
LogFilePath is path for saving result log
Commonly used Parameters are as described below:
/a :  fc displays only the first and last line for each set of differences.
/b : Compares the files in binary mode.
/c : Ignores the case of letters.
/l :  Fc compares the two files line by line and attempts to resynchronize the files after finding a mismatch. 
/lbn : Sets the n number of lines for the internal line buffer.
/n : Displays the line numbers during an ASCII comparison.