You can use Linux diff command to compare two files line by line. Let’s explain with some examples.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
## compare two files with diff command (normal output) ## Normal Output: ## ## ## change_type: ## a ==> something has been added ## c ==> something has been changed ## d ==> something has been deleted echo -e "one\ntwo\nthree\nfour" > myfile1 ## create some files echo -e "one\ntwo\nthree\nfour" > myfile2 diff myfile1 myfile2 ## returns nothing echo -e "one\ntwo\n3\n4" > myfile2 ## change line 3 and 4 in target file diff myfile1 myfile2 ## returns ## 3,4c3,4 ==> line 3 to 4 has been changed (c), lines are clubbed (3,4) with comma ## < three ==> < represents source value ## < four ## --- ==> --- denotes the difference ## > 3 ## > 4 ==> > represents target value echo -e "1\ntwo\n3\nfour" > myfile2 ## change line 1 and 3 diff myfile1 myfile2 ## returns ## 1c1 ==> line 1 has been changed (c), lines are not clubbed as change is not in consicutive lines ## < one ==> < represents source value ## --- ==> --- denotes the difference ## > 1 ==> > represents target value ## 3c3 ==> line 3 has been changed (c), lines are not clubbed as change is not in consicutive lines ## < three ==> < represents source value ## --- ==> --- denotes the difference ## > 3 ==> > represents target value echo -e "one\ntwo\nthree" > myfile2 ## delete line 4 diff myfile1 myfile2 ## returns ## 4d3 ==> line 4 is deleted (d) ## < four ==> < represents source value echo -e "one\ntwo\nthree\nfour\nfive" > myfile2 ## add new line 5 diff myfile1 myfile2 ## returns ## 4a5 ==> line 5 is added (a) ## > five ==> > represents target value rm my* |