line-numbers

Delete specific line number(s) from a text file using sed?

余生颓废 提交于 2019-11-26 19:16:11
I want to delete one or more specific line numbers from a file. How would I do this using sed? Brian Campbell If you want to delete lines 5 through 10 and 12: sed -e '5,10d;12d' file This will print the results to the screen. If you want to save the results to the same file: sed -i.bak -e '5,10d;12d' file This will back the file up to file.bak , and delete the given lines. Note: Line numbers start at 1. The first line of the file is 1, not 0. You can delete a particular single line with its line number by sed -i '33d' file This will delete the line on 33 line number and save the updated file.

C/C++ line number

女生的网名这么多〃 提交于 2019-11-26 17:01:06
In the sake of debugging purposes, can I get the line number in C /C++ compilers? (standard way or specific ways for certain compilers) e.g if(!Logical) printf("Not logical value at line number %d \n",LineNumber); // How to get LineNumber without writing it by my hand?(dynamic compilation) 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

Show line number in exception handling

戏子无情 提交于 2019-11-26 13:58:25
问题 How would one display what line number caused the error and is this even possible with the way that .NET compiles its .exes? If not is there an automated way for Exception.Message to display the sub that crapped out? try { int x = textbox1.Text; } catch(Exception ex) { MessageBox.Show(ex.Message); } 回答1: Use ex.ToString() to get the full stack trace. You must compile with debugging symbols (.pdb files), even in release mode, to get the line numbers (this is an option in the project build

How do I get the current line number?

旧城冷巷雨未停 提交于 2019-11-26 12:58:23
Here is an example of what I want to do: MessageBox.Show("Error line number "+CurrentLineNumber); Current line number will be the line number in the source code of this piece of code. How can I do that? 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: static void SomeMethodSomewhere() { ShowMessage("Boo"); } ... static void ShowMessage(string message, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null) { MessageBox.Show(message + " at line " + lineNumber + " (" + caller + ")"); }

Add line numbers to source code in vim

廉价感情. 提交于 2019-11-26 10:09:56
问题 How can I add line numbers to a range of rows in vim? Not as in \":set nu\" - this just displays numbers, but doesn\'t add them to the file. 回答1: With :%s/^/\=line('.')/ EDIT: to sum up the comments. This command can be tweaked as much as you want. Let's say you want to add numbers in front of lines from a visual selection ( V + move), and you want the numbering to start at 42. :'<,'>s/^/\=(line('.')-line("'<")+42)/ If you want to add a string between the number and the old text from the line

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

两盒软妹~` 提交于 2019-11-26 09:53:25
问题 I require help to search a text file (log file) using c# and display the line number and the complete line that contains the search keyword. 回答1: 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

How can I determine the current line number in JavaScript?

空扰寡人 提交于 2019-11-26 09:22:18
问题 Does JavaScript have a mechanism for determining the line number of the currently executing statement (and if so, what is it)? 回答1: var thisline = new Error().lineNumber If that doesn't work in whatever environment you're using, you can try: var stack = new Error().stack Then hunt through the stack for the line number. 回答2: you can use function test(){ console.trace(); } test(); 回答3: A bit more portable between different browsers and browser versions (should work in Firefox, Chrome and IE10+)

C/C++ line number

依然范特西╮ 提交于 2019-11-26 05:00:01
问题 In the sake of debugging purposes, can I get the line number in C /C++ compilers? (standard way or specific ways for certain compilers) e.g if(!Logical) printf(\"Not logical value at line number %d \\n\",LineNumber); // How to get LineNumber without writing it by my hand?(dynamic compilation) 回答1: 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

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

二次信任 提交于 2019-11-26 03:17:06
问题 Is there a way to display the lines in the stack trace for the .NET assembly build/deployed in Release mode? UPDATE: My application is divided into three class library projects and one ASP.NET \"website\" project. The error I am trying to track down is in one of the three class library projects. I only deployed the pdb file for the class library project that is generating the \"Object reference not set to an instance of an object\" error. The line numbers are still not showing up in the stack

How do I get the current line number?

我的梦境 提交于 2019-11-26 03:08:56
问题 Here is an example of what I want to do: MessageBox.Show(\"Error line number \"+CurrentLineNumber); Current line number will be the line number in the source code of this piece of code. How can I do that? 回答1: 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: static void SomeMethodSomewhere() { ShowMessage("Boo"); } ... static void ShowMessage(string message, [CallerLineNumber] int lineNumber = 0,