line-numbers

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

。_饼干妹妹 提交于 2019-12-17 03:22:16
问题 I want to delete one or more specific line numbers from a file. How would I do this using sed? 回答1: 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. 回答2: You can delete a particular single line with its line

How to know from which line a script is called?

陌路散爱 提交于 2019-12-11 19:58:38
问题 I would like to know from which line a script is called. Code: ... line 500 line 501 an <silent> 98.80.00 &Files.Test\ single\ :call Func('%')<CR> line 502 etc desired output: 501 Is it possible? 回答1: Apart from the question about "do you really need this?", here is a trick: "foo "bar let a = 5 let a = 5 let a = 5 call Foo(search('very special string')) let a = 5 let a = 5 fun! Foo(callerLineNumber) echo a:callerLineNumber endf this will print the line number of line call Foo(search('"very

java - inserting text using JTextArea by number line

左心房为你撑大大i 提交于 2019-12-10 23:28:35
问题 For my case, I want to insert text inside JTextArea by number line. For e.g name : andy birth : jakarta, 1 jan 1990 number id : 01011990 01 age : 26 study : Informatics engineering So, I want to insert text in last position in line 3. I think I can use: jTextArea.getDocument.insertString(3," my text here".null); but it doesn't work. So, I wish my output to be like this. name : andy birth : jakarta, 1 jan 1990 number id : 01011990 01 my text here age : 26 study : Informatics engineering 回答1:

Using PHP's XMLReader, how do I get the line number of the current node?

泪湿孤枕 提交于 2019-12-10 18:32:01
问题 Using the XMLReader XML parser in PHP 5.3, I need to get the line number of the current node. A column number or total offset from the beginning of the file would be nice, too. Hopefully I don't have to use some hack like parsing every raw node string for newlines (with readOuterXML() ), but I don't see a getLineNo() property like in the DOM... 回答1: See XMLReader::expand which returns a DOMNode element, which in turn supports getLineNo() 来源: https://stackoverflow.com/questions/2530679/using

hunspell: Printing the line number of the corrected word

白昼怎懂夜的黑 提交于 2019-12-10 15:20:41
问题 I am trying to use hunspell to correct an essay i have written. Unfortunately it is useless to me, as long as it doesn't print the line number of the word, which it predicts to be misspelled. So right now I am using the -a option, to be able to pipe it into hunspell . The man page says, that the -L option would "Print lines with misspelled words.". But I don't see any difference in the output. This is what I do right now: cat myessay.txt | hunspell -d en_US,de_DE -a -L An example output looks

Line Numbers, Code Highlighting in TextView

☆樱花仙子☆ 提交于 2019-12-10 09:47:22
问题 I'm working on an 'IDE' for Android - it could be useful for editing short scripts / making quick adjustments to files. At the moment I'm just using a simple EditText, but I am wanting to add several features, for example Line Numbering down the left hand side of the EditText and Code Highlighting. Does anyone have any suggestions about how to approach this? For the code highlighting, I'm guessing I'll need to write my own subclass of EditText. For the line numbering, could I have a thin

How to activate revision info in line number view

倖福魔咒の 提交于 2019-12-09 16:38:05
问题 I know of an Eclipse feature to show revision information (gradual coloring, more info like revisionnumber, date and author on mouseover) for the last changes in a line in the linenumbers-view. Does anyone know how to activate this feature for a file, or even better, by default? I accidently hit some shortcut lately which made it show in one file, it does not show up in the others, though. 回答1: This is called "Show Annotation" and you can find it in the "Team" menu. Since this is a pretty

Current file line number with $. variable

*爱你&永不变心* 提交于 2019-12-08 16:10:24
问题 I understand that I can get the current line number of a file I am looping through with the builtin variable $. . As an experiment, I used that to prefix each line in a file with the value of $. (the current line number). However, this did not work as expected. I.e. given the following file contents line one line two line three then I would expect the following code to prefix each line with its line number for my $line (<FILE>) { print "$. : $line"; } but, instead, it gives the following

When processing a file, how do I obtain the current line number?

谁都会走 提交于 2019-12-08 15:58:17
问题 When I am looping over a file using the construct below, I also want the current line number. with codecs.open(filename, 'rb', 'utf8' ) as f: retval = [] for line in f: process(line) Does something akin to this exist ? for line, lineno in f: 回答1: for lineno, line in enumerate(f, start=1): If you are stuck on a version of Python that doesn't allow you to set the starting number for enumerate (this feature was added in Python 2.6), and you want to use this feature, the best solution is probably