w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to stream input line by line in UNIX, perform commands on each line, and immediately return output?
You can use echo "${#line}" to know the length of a string. Reading the file with a while read... will do the rest: $ cat file hello my name is fedor qui $ while read line; do echo "${#line}"; done < file 5 7 8 3 0 In a nicer format: while read line do echo "${#line}" done < file

Categories : Shell

My code is working and the first line is displaying correctly but the second line is concatenated with the first line etc
Change $(".Weight").text(weight + unit); to $(".Weight", this).text(weight + unit); so that only the .Weight cell of the current row is changed. A prevision following comments : it's useless to cache selectors here, there wouldn't be any noticeable gain and it makes the code harder to read and maintain using children is slower, which isn't very important. What's important is that using children departs from the semantic use of classes, it makes your code rely on the fact the .Weight element is a direct child and not, for example a span in a td. That's exactly the same reason than why you should generally prefer closest over parent.

Categories : Jquery

Draw straight line and create curve line dragging line
Second touch - hold a variable to track your state. Curve - don't try to change a path, just use the start and end of the first line and create a UIBezierPath to draw as the user moves the touch point. Move the bezier to the start point, then use addCurveToPoint:controlPoint1:controlPoint2: using the end point and the current touch location. To make it really fun, allow the user to touch with 2 fingers while drawing the second line and then you have values for both of the control points.

Categories : IOS

reading file line by line , modify the line and write this line on same file. Python
Because you've used .split on the line, you're working with a list of strings. While a string is conceptually just a list of characters, it's still not a list of strings. Try using the .join method of a string to join your array before you write it out, for example: ''.join(["one, two"]) == "onetwo"

Categories : Python

unix command line cut and remove new line, unwrap next line
This awk one liner can do it: $ awk '{if ($0 ~ /&$/) {getline a; print $0,a} else {print }}' file it gets the lines ending with & and joins them with the next one. Otherwise just prints the line. Test $ awk '{if ($0 ~ /&$/) {getline a; print $0,a} else {print }}' file A7233334 PALLETS 2 11.000 EACH 2331 Storm Supply 247.5000 2,722.50 2,722.50 4144 Gentro Sales 225.0000 2,475.00 2,475.00 5155 Wacca Outfit 225.0000 2,475.00 2,475.00 6661 Acme Warehouse & Fuller Supply 225.0000 2,475.00 2,475.00 1661 McHugh & Donaldson

Categories : Unix

Python 3 - Reading line by line from a textfile and doing action for each line
urlFile = "path/to/file" urls = open(urlFile).readLines() for url in urls: doAction(url) OR you could just put it all in the url file reading loop; with open(urlFile) as f: for line in f: doAction(line)

Categories : Python

Bash: loop through file line by line, find specific string and append to each subsequent line until same string is found
If I have your requirements right, this little awk program will work: awk '/^AB1/{ab1=$0;next}/^AB2/{print $0, ab1}' That will do nothing with any line which doesn't start with AB1 or AB2 and it fails to check for equality of the 12-character string following the AB1/AB2. I couldn't tell if you require that check.

Categories : Regex

Matplotlib fill blank image line by line, when I receive data from socket
It's unnecessary to create a new image every time new data arrives from the socket. You can create a single image on initialisation, then update the values in the array from the data you are receiving: # on initialisation self.im = imshow(np.zeros((x,y)),cmap='gray',interpolation='nearest', origin='lower') ... # on update self.im.set_data(self.values) self.im.set_clim(self.values.min(),self.values.max()) self.im.figure.canvas.draw()

Categories : Python

Extract a numeric substring and another line as variables from multi-line text file
You could use the following regex for the second line: ^.*(d{6})[^d].*$ Here, the first named sub-group would denote the digits of interest. For example, using Notepad++, Orginal text: Replace options: Resulting text: The regex should remain more or less the same across environments. You might need to simply change the way the named subexpression ($1 here) is referenced.

Categories : Regex

How to Calculate and Draw Dimension Line (line with perpendicular end lines) in iOS using Core Graphics?
The following code computes a vector of length 1 that is perpendicular to the line from p = (x, y) to p1 = (x1, y1): CGPoint p = CGPointMake(x, y); CGPoint p1 = CGPointMake(x1, y1); // Vector from p to p1; CGPoint diff = CGPointMake(p1.x - p.x, p1.y - p.y); // Distance from p to p1: CGFloat length = hypotf(diff.x, diff.y); // Normalize difference vector to length 1: diff.x /= length; diff.y /= length; // Compute perpendicular vector: CGPoint perp = CGPointMake(-diff.y, diff.x); Now you add and subtract a multiple of that perpendicular vector to the first point to get the endpoints of the first marker line at p: CGFloat markLength = 3.0; // Whatever you need ... CGPoint a = CGPointMake(p.x + perp.x * markLength/2, p.y + perp.y * markLength/2); CGPoint b = CGPointMake(p.x - perp.x * mar

Categories : IOS

Draw / Write on an image more than one line - EmguCV (OpenCV) does not recognize new line char
You can always make your own function that parses the paragraph into individual lines and then produce the y-displacement needed for each row. If I remember correctly, the default font size is 16 pixels. void myDrawMultiLineText(string InputParagraph, Point Origin) { vector<string> LinesOfText = myParse(InputParagraph," "); for (int i=0;i<LinesOfText.size(); ++i) DrawText(CurrentLine[i], Origin.x, Origin.y + i*16); }

Categories : C#

Objective C - Create text file to read and write line by line in Cocoa
Well, to create a file, just use [[NSFileManager defaultManager] createFileAtPath:@"Your/Path" contents:nil attributes:nil]; This creates an empty file, which you can write to or read from. To write text (or XML), just use NSString's writeToFile:atomically:encoding:error: method like this NSString *str = //Your text or XML [str writeToFile:"Your/Path" atomically:YES encoding:NSUTF8StringEncoding error:nil]; To read from a file, just make an NSString with the contents of that file NSString *contents = [NSString stringWithContentsOfFile:@"Your/Path"]; or, if it does not contain a string, get an NSData object from the file NSData *contents = [NSData dataWithContentsOfFile:@"Your/Path"];

Categories : Objective C

Java vertical line behind text? Like the line in an editor that indates where a page ends
I'm not entirely sure what you're doing, but it seems to me like you could get a decent solution by adding an element in your JList that looks something like "-------------------" where a page break would be so that it displays. I'm not sure if that's what you're looking for though.

Categories : Java

How to read data from Excel and write it to text file line by line?
You should open the output.txt file with append mode: file = open("Output.txt", "a") Also, you should do this before entering the loop, and it should be closed after that loop. Update: In cases like this one, you could use with instead of closing the file handle at the end. Also including the good suggestion made by @Josh in his own answer, the code could be this: import xlrd import os.path wb = xlrd.open_workbook(os.path.join('D:TRB 2014 Data','SPS1 demo data.xlsx')) wb.sheet_names() sh = wb.sheet_by_index(0) i = 1 with open("Output.txt", "a") as my_file: while sh.cell(i,11).value != 0: Load = sh.cell(i,11).value all_d = sh.col_values(i, 13, 19) DB1 = Load + " " + (" ".join(all_d)) my_file.write(DB1 + ' ') i += 1

Categories : Python

Groovy - Adding a line in middle of a file without modifying new line characters
I believe your solution handles this case, but keep in mind this can get tricky for input files such as: // Dangerous comment // // import com.oldcompany.Bogus; import com.foo.Example; public MyClass { } However, both your solution (and mine) will fail if there is no import: // random comment // public MyClass { } Assuming there must be an import, here is one way to do it, using regular expressions: def addIfRequired = { def directory, def filePath -> def inputFile = new File(filePath) boolean containsPackage = false; List<String> lines = inputFile.readLines(); for (def eachLine : lines) { eachLine = eachLine.trim(); if (eachLine.startsWith("package ")) { containsPackage = true break } else if (eachLine.st

Categories : Groovy

javascript how to read line by line from a local text fie and display in a listbox
You can't access to the local file system, because that would mean you can read all the files on one's computer. Howewer, you can get a particular file when the user drag and drops that file into an element. Here's an example that shows you the content of the file if it is a txt document: http://html5demos.com/drag-anything

Categories : Javascript

Visual Basic - Writing / Overwriting into a text line adds a new line
Going on the information from the question and comments, it seems that your file will end up with an additional linefeed at the end in both cases (ie. both for new and modified files). The reason for this is that you're using the WriteLine method, which will append a newline at the end of the text it writes, even if that text already ends with a newline. Simply change the code to use the Write method instead of the WriteLine method and you should end up with a file that contains only the text passed to the method.

Categories : Visual Studio 2010

search for a string and delete duplicates and add new line to second and last line of a text using bash
From what I can tell, you want to delete the second occurrence of <?xml ... ?> and wrap everything in the <frame> tag using only command line tools. This can all be done with a sed one-liner sed '0,/<?xml.*>/! s/<?xml.*>//g' -e '2i <frame>' -e '$a </frame>' The first expression deletes all <?xml ... ?> tags excluding the first one, the second expression inserts <frame> at line 2, and the third expression appends </frame> at the end.

Categories : Xml

AIX Shell Script - Formatting a long line of 255 Characters into a 10 line paragraph
How about this? echo "Life is not about searching for the things that could be found. It's about letting the unexpected happen. And finding things you never searched for. Sometimes, the best way to move ahead in life is to admit that you've enough" | fmt -w 30 Result: Life is not about searching for the things that could be found. It's about letting the unexpected happen. And finding things you never searched for. Sometimes, the best way to move ahead in life is to admit that you've enough

Categories : Shell

Removing the new line character from javascript and making the data come in single line
Don't use new RegExp. Just use the string replace method. justiread..replace(/( | | )/gm,"") The "g" switch is global replace, "m" means it should happen more than once. See http://www.textfixer.com/tutorials/javascript-line-breaks.php

Categories : Javascript

Why can one line of code work, but then the same line throws a null pointer exception later?
On the third line of your onStart method you are setting the context to the activity. Try setting it to the context instead. this.context = getActivity().getApplicationContext();

Categories : Java

linux shell: prepend or append text to next line after matching line
If you're confused on the general text-piping linux applications, I would recommend going through this exercise on the Learn Linux the Hard Way course. Should take 4-5 minutes and help quite a bit.

Categories : Linux

In Java, how do I read the content line by line of another console application that's running?
ProcessBuilder in java provides a way to execute an external OS command and pipe input and read output from the external command. Here is a sample which does that: List<String> command = new ArrayList<String>(); command.add("/path/to/Blockland.exe"); command.add("Other arguments"); ProcessBuilder procBuilder = new ProcessBuilder(command); Process proc = procBuilder.start(); ProcessOutputReader outputReader = new ProcessOutputReader(proc.getInputStream()); ProcessOutputReader errorReader = new ProcessOutputReader(proc.getErrorStream()); Thread out = new Thread(outputReader); out.start(); Thread error = new Thread(errorReader); error.start(); proc.waitFor(); Where ProcessOutputReader is a class that implements Runnable. It starts reading from the stream provided in

Categories : Java

Assigning variables to values in a text file with 3 columns, line by line
while read x y z; do echo x=$x y=$y z=$z done < input.txt The above requires that none of your columns contain any whitespace. EDIT: In response to comments, here is one technique to handle numbering the lines: nl -ba < input.txt | while read line x y z rest; do ~/data/standard/MNI152_T1_2mm -mul 0 -add 1 -roi $x 1 $y 1 $z 1 0 1 point -odt float > NewFile$line done

Categories : Bash

how to read multiline output command line by line, in a shell script?
Maybe I found a different solution, where I can use variables also outside the loop I have to change the default IFS to newline echo Searching for android virtual devices ... IFS=$' '; for l in $(${PROGDIR}/android list avd) ; do VAR1=$(echo $l | cut -d: -f1 | sed -e 's/s*//'); #sed removes trailing blanks if [ $VAR1 == "Name" ]; then NUM_AVD=$(($NUM_AVD+1)); fi; done echo "NUM_AVD=$NUM_AVD" In this case NUM_AVD is correctly 2

Categories : Shell

Highcharts Line - When Y axis min is set to 0, connecting line isn't shown for consecutive 0 values
Unfortunately it is known bug, reported to our developers here https://github.com/highslide-software/highcharts.com/issues/1687 You can try to set min value or threshold: http://api.highcharts.com/highcharts#plotOptions.series.threshold http://api.highcharts.com/highcharts#yAxis.min

Categories : Highcharts

R - Export line by line while transforming data, adding "" in places and not others while also removing NA
If I understand correctly, I think the function write.table() does everything you want. Rather than "transforming" your data as you write it, cant you just modify the dataframe until it has the format you want? For example, to get the UserID column to write out as a string, just convert that column to strings before writing the table, e.g. myData$UserID<-as.character(myData$UserID) Once the dataframe is correctly formatted, it should be as easy as write.table(myData,outFilePath,sep=",",na="",row.names=FALSE) Note the na="" argument, which tells it how to format NA values. For the footer row, you could deal with that separately, and use the "append=TRUE" argument.

Categories : R

Node.js: Why on data event from cmd /c dir spawn doesn't output 'line by line'?
Because this is just a pure data stream from the child process's standard output. There is no knowledge of whether that data is in any particular format, or whether it will contain any specific characters at all. So the data is treated like a stream of bytes and handled in chunks with no regard for the content or meaning of those bytes. That's the most general form of piping data around the system. Note, however, that there are wrapper streams that will buffer the raw data stream and give you a series of lines of text. You will find many modules for this on npmjs.org

Categories : Node Js

What's the advantage of having multi-line & single-line string literals in python?
The advantage of having to be explicit about creating a multi-line string literal is probably best demonstrated with an example: with open("filename.ext) as f: for line in f: print(line.upper()) Of course, any decent syntax-highlighting editor will catch that, but: It isn't always the case that you're using a syntax-highlighting editor Python has no control over what editor you are using. Two of Python's design principles are that errors should never pass silently, and explicit is better than implicit. Outside docstrings, multi-line strings are rarely used in Python, so the example above is much more likely to occur (everyone mistypes sometimes) than the case where you want a multi-line string, but forgot to explicitly say so by triple-quoting. It's similar to Pyth

Categories : Python

sending text file from server to client line by line in winsocks
You need to also send a newline. getline reads all characters until a newline, but doesn't store the newline in the string. So when you send the string, it doesn't have a newline. You can either send a " " on its own, but probably better to add a newline to the existing string. E.g. : stringToUpper(STRING); STRING += " "; ...

Categories : C++

how to center a semi transparent img on a horizontal line, without letting appear the line below the image?
Couldn't you just make an image in Photoshop that has the line and all the specifications you want. Something like <hr><img src="SRC"><hr> wouldn't work because it would break into two lines (see this fiddle). EDIT: According to your updated fiddle, you figured it out. In terms of better ways of doing this, I think that your way would work, although you would want to test it on a mobile device or shrunken browser to test its responsiveness. When I test its responsiveness on the fiddle, it seems to work in a smaller browser, although it breaks when it gets too small (about 40 px); however, no screen is so small that it would break. Long story short, use the fiddle you posted. http://jsfiddle.net/j4eH8/4/

Categories : CSS

How to read the input(line by line) from a multiline Tkinter Textbox in Python?
From the document, the get method on tkinter.text will just return the string, including the new line . You can not treat the tkinter.text as file, but you can use other ways. Read them all and split them into a list. Loop the list then. def retrieve_input(): text = self.txt.get('1.0', END).splitlines() for line in text: ... Using io.StringIO to emulate a file, but in this case it will not strip the newline. def retrieve_input(): text = io.StringIO(self.txt.get('1.0', END)) for line in text: line = line.rstrip() ...

Categories : Python

indexing of large text files line by line for fast access
Take the 43GB file in chunks that fit comfortably in memory and sort on the subject. Write the chunks separately. Run a merge sort on the chunks (sorted by subject). It's really easy: you have as input iterators over two files, and you write out whichever input is less, then read from that one again (if there's any left). Now you just need to make one pass through the sorted data to gather the groups of subjects. Should take O(n) space and O(n log n) time, which for this sort of thing you should be able to afford.

Categories : Scala

System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '6' and line position '10
@HighCore is right, using application solves your issue in the given scenario <ImageBrush ImageSource="pack://application:,,,/Resources/ClientBackground.png"/> You still can use siteoforigin. For that you have to set the image property Copy to Output Directory to "Copy always" MSDN Link

Categories : C#

Reading input files by line using read command in shell scripting skips last line
DONE=false until $DONE do read line || DONE=true echo $line done < blah.txt How to use `while read` (Bash) to read the last line in a file if there’s no newline at the end of the file?

Categories : Bash

Compare a text file line by line with a dynamic variable
If I understand the question correctly, this is what you need: File insert = new File("sample.txt"); BufferedReader br = new BufferedReader(new FileReader(insert)); String strLine; Boolean hasLine = false; while ((strLine = br.readLine()) != null) { if(strLine.equals(field)) { hasLine = true; break; } } br.close(); if (!hasLine) { FileWriter fw = new FileWriter(insert, true); BufferedWriter bw = new BufferedWriter(fw); bw.append(field + " "); // assumes field does not already have a newline bw.flush(); bw.close(); } Notice the break;. This will discontinue the while loop, since you already have the answer to what you are looking for. Your original code was doing: for every line: Do I equal field? Yes: goto next line No: append f

Categories : Java

Recursive method that prints the digits of the number line by line
If number consists of more than one digit print ( n / 10 ) print ( n % 10 ) If you want them printed in the other order print ( n % 10 ) If number consists of more than one digit print ( n / 10 )

Categories : Java

Replace a line in the file using sed, line has a moving portion in the center of it
Which part do you need help with? sed 's/^aaa.*bbb$/aaa_TEST_bbb/' file >newfile If you want to edit the file in place, remove the redirection and add a suitable -i option (provided your sed supports it).

Categories : Regex

Split line comma at end of line and exclude special cases
Matching a comma at the end of the string is done with an anchor: /,$/m The /m modifier is used to enable multiline mode, in which $ will match the end of the line instead of the standard end-of-subject.

Categories : Regex

How to arrange Thumbs with a Line for moving a line in a WPF custom Adorner
You'll need to handle the MouseDown, MouseMove and MouseUp events on the line to be able to do that: Add handlers for those events in the constructor selectedLine.MouseLeftButtonDown += SelectedLineOnMouseLeftButtonDown; selectedLine.MouseMove += SelectedLineOnMouseMove; selectedLine.MouseLeftButtonUp += SelectedLineOnMouseLeftButtonUp; And the implementation is something like this private Point origin; private void SelectedLineOnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { e.Handled = true; Line line = (Line) sender; line.CaptureMouse(); startPoint = new Point(line.X1, line.Y1); endPoint = new Point(line.X2, line.Y2); origin = e.GetPosition(line); base.OnMouseLeftButtonDown(e); } private void SelectedLineOnMouseMove(object sender, Mo

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.