Git diff with line numbers (Git log with line numbers)

You can’t get human-readable line numbers with git diff There aren’t currently any options to get line-numbers displayed vertically on the side with git diff. Unified-diff format That information is available in the (c)hunk headers for each change in the diff though, it’s just in unified-diff format: @@ -start,count +start,count @@ The original state of … Read more

search text file using c# and display the line number and the complete line that contains the search keyword

This is a slight modification from: http://msdn.microsoft.com/en-us/library/aa287535%28VS.71%29.aspx int counter = 0; string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(“c:\\test.txt”); while((line = file.ReadLine()) != null) { if ( line.Contains(“word”) ) { Console.WriteLine (counter.ToString() + “: ” + line); } counter++; } file.Close();

C/C++ line number

You should use the preprocessor macro __LINE__ and __FILE__. They are predefined macros and part of the C/C++ standard. During preprocessing, they are replaced respectively by a constant string holding an integer representing the current line number and by the current file name. Others preprocessor variables : __func__ : function name (this is part of … Read more

How do I get the current line number?

In .NET 4.5 / C# 5, you can get the compiler to do this work for you, by writing a utility method that uses the new caller attributes: using System.Runtime.CompilerServices; static void SomeMethodSomewhere() { ShowMessage(“Boo”); } … static void ShowMessage(string message, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null) { MessageBox.Show(message + ” … Read more

Number of lines in a file in Java

This is the fastest version I have found so far, about 6 times faster than readLines. On a 150MB log file this takes 0.35 seconds, versus 2.40 seconds when using readLines(). Just for fun, linux’ wc -l command takes 0.15 seconds. public static int countLinesOld(String filename) throws IOException { InputStream is = new BufferedInputStream(new FileInputStream(filename)); … Read more

Display lines number in Stack Trace for .NET assembly in Release mode

Go into the Properties window for the project where you want to see stack trace line numbers. Click on the Build “vertical tab”. Select “Release” configuration. Check the DEBUG constant parameter. Uncheck the “Optimize code” parameter to avoid the occasional trace issue with inlined code (this step is not essential). Press the Advanced… button and … Read more