lines

displaying multiple lines of a file, never repeating

好久不见. 提交于 2019-11-26 18:35:24
问题 i need to, for every ten lines, echo them in a div. example: <div class='return-ed' id='1'> line 1 line 2 ... line 9 line 10 </div> <!-- next group of lines --> <div class='return-ed' id='2'> line 11 line 12 ... line 19 line 20 </div> does anyone know a way to do this? array is from file(), so its lines from a file. 回答1: This should work: $blocks = array_chunk(file('path/to/file'), 10); foreach($blocks as $number => $block) { printf('<div id="%d">%s</div>', $number+1, implode('<br/>', $block)

Find duplicate lines in a file and count how many time each line was duplicated?

六眼飞鱼酱① 提交于 2019-11-26 16:50:41
Suppose I have a file similar to the following: 123 123 234 234 123 345 I would like to find how many times '123' was duplicated, how many times '234' was duplicated, etc. So ideally, the output would be like: 123 3 234 2 345 1 wonk0 Assuming there is one number per line: sort <file> | uniq -c You can use the more verbose --count flag too with the GNU version, e.g., on Linux: sort <file> | uniq --count Andrea This will print duplicate lines only , with counts: sort FILE | uniq -cd or, with GNU long options (on Linux): sort FILE | uniq --count --repeated on BSD and OSX you have to use grep to

Skip first couple of lines while reading lines in Python file

不打扰是莪最后的温柔 提交于 2019-11-26 12:20:57
问题 I want to skip the first 17 lines while reading a text file. Let\'s say the file looks like: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 good stuff I just want the good stuff. What I\'m doing is a lot more complicated, but this is the part I\'m having trouble with. 回答1: Use a slice, like below: with open('yourfile.txt') as f: lines_after_17 = f.readlines()[17:] If the file is too big to load in memory: with open('yourfile.txt') as f: for _ in range(17): next(f) for line in f: # do stuff 回答2: Use

How to place arrow head triangles on SVG lines?

别来无恙 提交于 2019-11-26 10:08:51
问题 I am new to SVG and I am trying to draw a straight line between two points. I managed so far by using this command: <line x1=\"50\" y1=\"50\" x2=\"150\" y2=\"150\" style=\"stroke:rgb(255,255,0); stroke-width:2\" stroke-dasharray=\"5,3\" />\" What is the simplest way to add tiny triangles or arrow heads (evenly spaced) over this line in order to indicate the direction? Edit 1: Just to be more clear, I am not after an arrow at the end of the line, but multiple triangles (evenly spaced) along

Efficient maths algorithm to calculate intersections

放肆的年华 提交于 2019-11-26 09:18:06
问题 For a game I am developing I need an algorithm that can calculate intersections. I have solved the problem, but the way I have done it is really nasty and I am hoping someone here might have a more elegant solution. A pair of points represent the end points of a line drawn between them. Given two pairs of points, do the drawn lines intersect, and if so, at what point? So for example call the lines (A.x, A.y)-(B.x, B.y) and (C.x, C.y)-(D.x, D.y) Can anyone think of a solution? A solution in

Batch / Find And Edit Lines in TXT file

社会主义新天地 提交于 2019-11-26 09:08:50
问题 I want to create a batch while which finds specific lines in a batch file and are able to edit these lines. Example: //TXT FILE// ex1 ex2 ex3 ex4 i want to let the batch file find \'ex3\' and edit this to \'ex5\' to let it look like this: ex1 ex2 ex5 ex4 回答1: On a native Windows install, you can either use batch(cmd.exe) or vbscript without the need to get external tools. Here's an example in vbscript: Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "c:\test\file.txt" Set

Python how to read N number of lines at a time

余生颓废 提交于 2019-11-26 08:08:26
问题 I am writing a code to take an enormous textfile (several GB) N lines at a time, process that batch, and move onto the next N lines until I have completed the entire file. (I don\'t care if the last batch isn\'t the perfect size). I have been reading about using itertools islice for this operation. I think I am halfway there: from itertools import islice N = 16 infile = open(\"my_very_large_text_file\", \"r\") lines_gen = islice(infile, N) for lines in lines_gen: ...process my lines... The

Find duplicate lines in a file and count how many time each line was duplicated?

北战南征 提交于 2019-11-26 04:56:48
问题 Suppose I have a file similar to the following: 123 123 234 234 123 345 I would like to find how many times \'123\' was duplicated, how many times \'234\' was duplicated, etc. So ideally, the output would be like: 123 3 234 2 345 1 回答1: Assuming there is one number per line: sort <file> | uniq -c You can use the more verbose --count flag too with the GNU version, e.g., on Linux: sort <file> | uniq --count 回答2: This will print duplicate lines only , with counts: sort FILE | uniq -cd or, with