lines

counting the number of lines in a text file (java)

不想你离开。 提交于 2019-12-12 09:59:57
问题 Below is how i count the number of lines in a text file. Just wondering is there any other methods of doing this? while(inputFile.hasNext()) { a++; inputFile.nextLine(); } inputFile.close(); I'm trying to input data into an array, i don't want to read the text file twice. any help/suggestions is appreciated. thanks 回答1: If you just want to add the data to an array, then I append the new values to an array. If the amount of data you are reading isn't large and you don't need to do it often

Ruby equivalent to “grep -C 5” to get context of lines around the match?

霸气de小男生 提交于 2019-12-12 08:51:51
问题 I've searched for this a bit but I must be using the wrong terms - does ruby have a way to grep for a string/regex and also return the surrounding 5 lines (above and below)? I know I could just call "grep -C 5 ..." or even write my own method, but it seems like something ruby would have and I'm just not using the right search terms. 回答1: You can do it with a regular expression. Here's the string we want to search: s = %{The first line The second line The third line The fourth line The fifth

Fastest way to skip lines while parsing files in Ruby?

独自空忆成欢 提交于 2019-12-12 07:51:32
问题 I tried searching for this, but couldn't find much. It seems like something that's probably been asked before (many times?), so I apologize if that's the case. I was wondering what the fastest way to parse certain parts of a file in Ruby would be. For example, suppose I know the information I want for a particular function is between lines 500 and 600 of, say, a 1000 line file. (obviously this kind of question is geared toward much large files, I'm just using those smaller numbers for the

Replace multiple lines from a file with mutiple lines from another

廉价感情. 提交于 2019-12-12 06:48:06
问题 Can I, in few commands, search and replace multiple lines in a file? I'm trying to replace the 3 failover blocks from dhcp_primary by the unique failover block from dhcp_secondary , within dhcp_primary . My goal is to copy the dhcpd.conf from a primary dhcp to the secondary (more information here: http://www.madboa.com/geek/dhcp-failover/). The failover work only if the configuration are identical, except the failover block of course; as you can see is the website's example. So I want to copy

How to insert two lines for every data frame using awk?

随声附和 提交于 2019-12-11 16:16:23
问题 I have repeating data as follows .... 4 4 4 66 79 169 150 0 40928 40938 40923 40921 40789 40000 40498 5 4 3 16 22 247 0 40168 40911 40944 40205 40000 40562 6 4 4 17 154 93 309 0 40930 40919 40903 40917 40852 40000 40419 7 3 2 233 311 0 40936 40932 40874 40000 40807 .... This data is made up of 115 data blocks, and each data block have 4000 lines like that format. Here, I hope to put two new lines (number of line per data block = 4000 and empty line) at the begining of each data blocks, so it

Use batch file to copy first 6 lines to a new txt file

こ雲淡風輕ζ 提交于 2019-12-11 13:14:32
问题 I have tried a dozen different ways and cannot get it right. I have many text files in different folders, so I would like to reference the input file as a variable eg: *.txt (just use whatever txt file is in the same folder as the bat file). I need to copy the first 6 lines and paste them into a new txt file. I would like to name it (but not essential) SAMPLE_original_txt_file_name EG: Input = text01.txt Output = SAMPLE_text01.txt (this would contain the first 6 complete lines from text01.txt

How to ignore all lines after a specific word on processing lines of a text file in a FOR loop?

狂风中的少年 提交于 2019-12-11 09:07:06
问题 My problem is solved about the columns not about the lines using skip=3 . This ignores the very 3 first lines. So what about ignoring all the lines after the first end word in the example below. 1121.19, 1638.66, 16.6098, -4.7339, -4.7339, 2.5, hash:0, -1, -1, -1, -1, 1888, 0, 0 971.597, 1815.17, 21.085, 1.39876E-006, 8, 4, hash:0, -1, -1, -1, -1, 1905, 0, 0 971.597, 1825.45, 21.085, 1.39876E-006, 8, 4, hash:0, -1, -1, -1, -1, 1905, 0, 0 end tcyc end mlop end lodm end slow end blok end So I

Python how to grab certain number of lines after match

怎甘沉沦 提交于 2019-12-11 08:36:54
问题 Let's say I have an input text file of the following format: Section1 Heading Number of lines: n1 Line 1 Line 2 ... Line n1 Maybe some irrelevant lines Section2 Heading Number of lines: n2 Line 1 Line 2 ... Line n2 where certain sections of the file start with a header line that specifies how many lines are in that section. Each section heading has a different name. I have written a regular expression that will match the header line based on the header name the user searches for each section,

Drawing a line in a class which extends "Activity'

拜拜、爱过 提交于 2019-12-11 08:09:00
问题 I have an ImageView loading a picture in my Activity and want to draw some lines on it. It seems like I'm not able to overlay the lines I draw onto the ImageView. If I create a new class (myPainter) which extends 'View', hook myPainter.onDraw() and then setContentView(mp) in onCreate() from the activity, all I get are the drawn lines. My ImageView is gone from onCreate(). How do I get the ImageView and lines to show up in the same layout? I'm also Override'ing onTouch() for the ImageView so I

drawing hierarchical tree with orthogonal lines ( HV-Drawing – Binary Tree)

泄露秘密 提交于 2019-12-11 07:52:58
问题 I need to work on drawing a hierarchical tree structure (HV-Drawing – Binary Tree) with orthogonal lines(straight rectangular connecting lines) between root and children ( like the following: http://lab.kapit.fr/display/visualizationlayouts/Hierarchical+Tree+layout ). I want to know if there are any open source examples of the algorithm of drawing trees like that so that I can implement the same algorithm in actionscript. Thanks Palash 回答1: I did a C# version and put the code up on