Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
 Read from text file, capture text, write to another text file in specific syntax I'd personally do something like that with Perl, because I'm familiar with Perl and it works great for these kinds of tasks. You can also write a sed one-liner to get that done. If you're not a fan of Perl, any modern dynamic language should let you get the job done with minimal effort. EDIT: An example Perl script (full file for readability) would look like this: use warnings; use strict; while (my $line = <>) {$line =~ /^s*(.+?), '(.+?)', '(.+?)';$/; # Doesn't handle internal escaping print "DELETE ATTRIBUTE "$1" IN FOLDER "$2" FROM PROJECT "$3"; "; } See the result. Categories : Misc Write an existing XML file without overwritting In the general case, you can write to a file in append mode using: new FileOutputStream(file, true); The second parameter is a boolean with true meaning append and false meaning overwrite. The default is false (as you have no doubt discovered). That being said, appending data to the end of an XML file probably does not make sense. It would be much better to use an XML reader to read the XML file into a Document object, add elements to that object, and then write that object back to disk. Categories : Java Can't write data to existing xlsx file I found out the answer . I just changed the line at OfficeOpenXml.ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Report System - " + DateTime.Now.ToShortDateString()); to OfficeOpenXml.ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheet1"]; and it worked !!. Because Sheet1 is the default name of worksheet and it existed in my file at line: string filePath = @"C: eport_data.xlsx"; Actually, in this case, package.Workbook.Worksheets.Add means to add the worksheet's name and I found that it didn't have to add the worksheet's name because it already exists. Categories : C# In node.js why i'm not getting error while trying to write the non existing file Because the writeFile function creates the file if it does not exist. Basically, you can change the behavior of this function by submitting an options object as third parameter, as described in the documentation. For the flags property you can provide any value from the ones described in the documentation for fs.open. For write, they are: w - Open file for writing. The file is created (if it does not exist) or truncated (if it exists). wx - Like w but opens the file in exclusive mode. w+ - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists). wx+ - Like w+ but opens the file in exclusive mode. The default value for writeFile is w, hence the file is created if it does not exist. As there is no option that provides an error when the Categories : Node Js Positional write to existing file [Linux, NodeJS] Open with a mode of r+ instead of a. r+ is the portable way to say that you want to read and/or write to arbitrary positions in the file, and that the file should already exist. Categories : Node Js how to write a batch file which can identify value from a text file and store that value in some other text file This example will work for integer numbers between spaces. Special caution must be put in text file, as behaviour for ", <, |, > and & may be unpredictable. Some optimizations may be made having more information about text file. For /F "Tokens=*" %%i In (TextFile.txt) Do Call :GetNumber %%i GoTo :EOF :GetNumber If "%~1"=="" GoTo :EOF Set Number= Set /A "Number=1*%~1" If "%Number%" == "%~1" Call :StoreNumber %Number% Shift GoTo :GetNumber :StoreNumber Echo %Number%>Number.txt Categories : Batch File how to read and write into existing xml file in metro javascript and html Answer in the following link is pretty much doing everything you want http://social.msdn.microsoft.com/Forums/windowsapps/en-US/a7847959-edcf-4175-b312-9a03746e29b9/create-xml-file-and-write-xml-data But that's not the only possible way of reading a file of course. Categories : HTML Append text to existing file Always use the Using statement when you work with classes that implement IDisposable. So for example instead of Dim reader As New StreamReader(Output) reader = File.OpenText(Output) this Using reader = File.OpenText(Output) ' do something with it End Using or instead of Dim tw As TextWriter = New StreamWriter(strDestinationFile) For x As Integer = 0 To DataGridView1.Rows.Count - 2 For y As Integer = 0 To DataGridView1.Columns.Count - 12 tw.Write(DataGridView1.Rows(x).Cells(12).Value) If y <> DataGridView1.Columns.Count - 1 Then tw.Write(Environment.NewLine) End If Next y tw.WriteLine() Next x tw.Close() this (dispose closes the stream implicitely) Using tw = New StreamWriter(strDestinationFile) For x As Integer = 0 Categories : Vb.Net how to write output of command "adb push file.txt /sdcard/" to text file? Assuming you are using bash, you can redirect stderr : adb push test.mp4 /sdcard/test.mp4 2> Result.txt or both stdout and stderr : adb push test.mp4 /sdcard/test.mp4 > Result.txt 2>&1 Categories : Perl Append to an existing text file using Photoshop Scripting ( .jsx ) You're currently "writing" to the file, not "appending". // open() method fileExample.open("w"); // write fileExample.open("e"); // edit fileExample.open("a"); // append You should be able to change Loginfo.open("w", "TEXT"); to Loginfo.open("a", "TEXT"); Categories : Javascript Modifying parameter in existing text file with Python You can use the fileinput module: import fileinput for line in fileinput.input('example.txt', inplace = True): if line.startswith('rx_b_phase'): #if line starts with rx_b_phase then do something here print "rx_b_phase = foo" elif line.startswith('sample_gain_hi'): #if line starts with sample_gain_hi then do something here print "sample_gain_hi = bar" else: print line.strip() Categories : Python Get file name of file being uploaded and write it into a text field just extract the last string before the last slash .. in your case v is what is returned and x is what you want var v = 'some\thing\text.txt'; var x =''; for(i=v.length-1;i>=0;i--) if(v[i]!='/' && v[i]!='\') x = v[i]+x; else break; console.log(x); Demo solution 2 : var v = 'some/thing/text.txt'; var y = v.split(/[\/]/); var x = y[y.length-1]; console.log(x); Demo Solution 3: var v = 'vava\text.txt'; console.log(v.replace(/.*[\/]/g,'')); Demo Categories : PHP Adding new column in between existing columns according to data in a text file Columns are only added at the end, because otherwise it can mess up existing INSERT SQL queries. You should not be concerned about how the db organizes itself - that's the whole point! later on just query out columns at your wanted order.. Categories : C# How do i write from textBox the text to text file and read back from the file to the textBox? No need for a StreamWriter or StreamReader, too much clutter and boilerplate. I would suggest txtSettings.Text = System.IO.File.ReadAllText(path_to_file); and on the Leave or Validated event from the textbox System.IO.File.WriteAllText(path_to_file, txtSettings.Text); Don't write to a file on each TextChanged event, or it will write to the file on each keystroke which would prove to be a major bottleneck. Either write to the file on Leave or (Form_Closed if it's in a dialog) or use a Timer to periodically save to the file (and keep track of changes with a boolean that you set to true in the TextChanged event). Categories : C# Write to web text file You may have to adjust the path directory, but this works: string path = Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile) + "\something\myfile.txt"; string previousNumber = System.IO.File.ReadAllText(path); int newNumber; if (int.TryParse(previousNumber, out newNumber)) { newNumber++; using (FileStream fs = File.Create(path, 1024)) { Byte[] info = new UTF8Encoding(true).GetBytes(newNumber.ToString()); fs.Write(info, 0, info.Length); } } Categories : C# How to write file size in kB to text file? Divide the size by 1024 to get it in kB and round the value to the appropriate number of digits (e.g. 2): For Each ObjFile In ObjFiles size = Round(ObjFile.size / 1024, 2) ObjOutFile.WriteLine size & String(50 - Len(size), " ") & ObjFile.Path Next Categories : Vbscript How do I write a text file into a Jar that is not currently running in the JVM JAR files are just ZIP files. You should be able to use the classes in the java.util.zip package to do what you want. A quick google search turns up a bunch of posts about how to use the package. Categories : Java Write into a text file with jQuery You can't write in files with Javascript/jQuery for security reasons because, if we could, a visitors would be able to change easily, with his console, the file url to edit and create consequent damages. For more explains, you can have a look to this page. So, to solve your problem, I think the best way to do is to create a php file, which will be able to update your server files, and to send to this php file the content of files to update with ajax. Categories : Jquery Read/write from text file in C++ Regarding output you could simply use a std::ofstream and replace where you use std::cout: inline std::ostream& os printPath(std::ostream& os, vectorpath) { os <<"[ "; for(int i=0;i 1) { std::ofstream ofs(argv{1]); // ... printPath(ofs,path) } } Regarding reading this format from a file, I'd suggest s.th. like this: std::ifstream ifs("MyGraphFile.txt"); while(ifs && !ifs.eof()) { std::string line = std::string::getline(ifs); // strip the '[' and ']' characters line = line.substr(1,line.length() - 2); std::istringstream iss(line); std::vect Categories : C++ write sql command to text file Frankly, replacing the parameters with values is (IMO) the wrong thing to do; what we do in mini-profiler is to spoof declare statements at the top of the output, so that you can copy and paste it into SSMS, without needing to worry about what is a parameter and what was hard-coded in the original TSQL. For example, glancing at the mini-profiler output for this page, I see DECLARE @id int = 18121022, @type tinyint = 10; (and then lots of tsql that is very specific to us) You can glance at the mini-profiler code to see how we output this, but basically it just involves walking over the parameters, writing a simple declare. If you are using something like ASP.NET, mini-profiler also avoids the need to write a file (instead making it available live on the site, to your developers) Categories : C# Write to middle of text file With standard Pascal File I/O you can only read, rewrite or append data in the file. If you want to change data in a certain position of the file you can use TFileStream: var f:TFileStream; PositionStr:String; PositionValue:Integer; begin f := TFileStream.Create('filename.log',fmOpenReadWrite); PositionValue := 200000; // new STOP Position PositionStr := IntToStr(PositionValue); f.Seek(100,soFromBeginning); // Data will be overwritten from position 100 f.WriteBuffer(PositionStr[1], length(PositionStr)); f.free; end; Categories : Delphi Write a text file using Python Use open with mode "a" to append the data. Using mode "w" will overwrite existing data. with open('myfile', mode='a') as fp: fp.write('data') Categories : Python how to write all the tags to text file you can use QRegularExpression for this see example below. QString txt = reply->readAll(); QRegularExpression regex("< *[pP] *>(.*)< *\/ *[pP] *>"); QRegularExpressionMatchIterator it = regex.globalMatch(txt); int i = 0; while(it.hasNext()) { QRegularExpressionMatch match = it.next(); QString filename = QString("e:/folder/file%1.txt").arg(i); QFile file (filename); file.open(QIODevice::WriteOnly); file.write(match.captured(1).toUtf8()); file.close(); ++i; } Categories : C++ How to add Sticky Notes, Insert Text at cursor, .. Annotations in existing PDF file using iTextSharp with C#? The iText(Sharp) example TimetableAnnotations1.java / TimetableAnnotations1.cs from chapter 7 of iText in Action — 2nd Edition shows how to add annotations to existing PDFs in general. The central code is (in the C# example): rect = GetPosition(screening); annotation = PdfAnnotation.CreateText( stamper.Writer, rect, movie.MovieTitle, string.Format(INFO, movie.Year, movie.Duration), false, "Help" ); annotation.Color = WebColors.GetRGBColor( "#" + movie.entry.category.color ); stamper.AddAnnotation(annotation, page); where stamper is a PdfStamper working on your PDF file; movie is a data structure the example retrieves title, text and color of the annotation from. PdfAnnotation offers multiple other Create... methods to create other types of annotations. Categories : C# How to write a text file in Acrobat Javascript All Acrobat JavaScript functions that write a file to the user’s local disk pose a security risk, so there are some restrictions placed on their use. These functions include doc.saveAs() and all of the data export functions, like doc.exportAsFDF(). As you can read here: Acrobat provides us with two modes of operation for these functions--with a path and without a path. If no path parameter is provided to the function, Acrobat displays a file-browser dialog. The file browser dialog gives users control over how data is saved to their systems. If a path is provided to the function, then no dialog is displayed and the operation is handled silently, i.e., the user is not necessarily aware that data has been saved to their hard drive. This is a security problem, so to use one Categories : Javascript How to write Burmese text into CSV file android Many would say, use a CSV library. Instead of Charset.forName("UTF-8").newEncoder() it suffices to use "UTF-8", but not wrong. Instead of " " under Windows " " might be more convenient. (System.getProperty("file.encoding") would take Android's " ".) You need to handle commas and quotes. If a string value contains a comma, then it should be withing double quotes. Every inner double quote self-escaped, that is doubled. Instead of a comma, also semi-colon is used. Even better is a tab character " ". To detect UTF-8, you may write a BOM character at the begin of file. This is a zero-width space. BOM = Byte Order Mark, refering to UTF-16LE and UTF-16BE (reversed byte pair). sb.append("uFEFF"); // Add a BOM at the begin of file. The file ending might be ".csv" but you may also lie, and Categories : Java Python: Write colored text in file You could check out Pygments with any suitable lexer and a TerminalFormatter. E.g. the following code: import sys from pygments import highlight from pygments.formatters.terminal import TerminalFormatter from pygments.lexer import RegexLexer from pygments.token import Token class ArithmeticLexer(RegexLexer): tokens = { 'root': [ (r'[ ]', Token.Whitespace), (r'd+', Token.Number), (r'+', Token.Plus), (r'-', Token.Minus), (r'*', Token.Multiply), (r'/', Token.Division), ] } COLOR_SCHEME = { Token.Whitespace: ('', ''), Token.Number: ('darkgreen', 'green'), Token.Plus: ('darkred', 'red'), Token.Minus: ('darkblue', 'blue'), Token.Multiply: ('darkyellow', 'yellow'), Token.D Categories : Python Efficient way to write a lot of lines to a text file I threw together a simple snippet that I think is a bit cleaner; but, then again, I'm not quite sure what you are trying to accomplish. Also, I don't have any of your classes available, so I can't really do any kind of tests. This sample does basically the same thing you have; except that it uses some generic methods, and it does all the writing in one spot. string filePath = "MickeyMoust.txt"; bool append = false; List myClassAs = new List { new MyClassA() }; List outputLines = new List(); foreach (MyClassA myClassA in myClassAs) { outputLines.Add(myIO.GetCharArray(myClassA)); if (myClassA.MyClassBs != null) outputLines.AddRange(myClassA.MyClassBs.Select(myClassB => myIO.GetCharArray(myClassB))); i Categories : C# Cannot write the output to a text file in cpp program You probably have the console input (scanf) confused with the file input (fscanf). The C-style functions for file I/O have an f prefix. See: fprintf, fscanf, fgets, and fputs. Categories : C++ write to a text file from HTML form using PHP Your submit button and input element and the form, have the same name "email". The first thing to do is to give them different names. The name of the form also includes an extra space "email ". Categories : PHP Write in a text file without overwriting in fs node js Check the flags here: http://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback - you are currently using w+ which: 'w+' - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists). You should use a instead: 'a' - Open file for appending. The file is created if it does not exist. 'ax' - Like 'a' but opens the file in exclusive mode. 'a+' - Open file for reading and appending. The file is created if it does not exist. 'ax+' - Like 'a+' but opens the file in exclusive mode. Categories : Javascript Write and read php object in a text file? You can use serialize() before saving it to the file and then unserialize() to get the whole $obj available to you:$obj = new stdClass(); $obj->name = "My Name";$obj->birthdate = "YYYY-MM-DD"; $obj->position = "My position";$objtext = serialize($obj); //write to file Then later you can unserialize():$obj = unserialize(file_get_contents($file)); echo$obj->birthdate;//YYYY-MM-DD Categories : PHP Write text to a file in Azure storage I'm assuming you're referring to storing a file in a Windows Azure blob. If that's the case: A blob isn't a file system; it's just a place to store data (and the notion of a file is a bit artificial - it's just... a blob stored in a bunch of blocks). To modify the file, you would need to download it and save it to local disk, modify it (again, on local disk), then do an upload. A few thoughts on this: For this purpose, you should allocate a local disk within your worker role's configuration. This disk will be a logical disk, created on a local physical disk within the machine your vm is running on. In other words, it'll be attached storage and perfect for this type of use. The bandwidth between your vm instance and storage is 100Mbps per core. So, grabbing a 10MB file, while on a Small Categories : Azure How To write to a specific part of a text file c# Just right-pad the parts to be the correct length (make sure it is not longer, and decide what to do if that occurs). Concatenate the parts and write it as a singe line. Categories : C# Create and write in text file with SSIS The below steps should help you to get a basic SSIS package working: Create new Integration Services Project in Business Intelligence Development Studio. There should be a default SSIS package in it called Package.dtsx. Open the package. In the bottom of the screen, there should be an area for connection managers. Right click on it to get a list of different connection managers. Click on New OLEDB Connection. This will be the connection manager for your source database. Set the data source (server or instance name), authentication mode and credentials and the initial catalog (database name). Again right click in the connection managers area and select New Flat File Connection.This will be the connection manager for the destination flat file. You can create a text file (.txt or .csv) and Categories : Sql Server Write output to text file in Powershell The simplest way is to just redirect the output, like so: Compare-Object $(Get-Content c:userdocumentsList1.txt)$(Get-Content c:userdocumentsList2.txt) > c:userdocumentsdiff_output.txt > will cause the output file to be overwritten if it already exists. >> will append new text to the end of the output file if it already exists. Categories : Powershell create multiple text file and write to it I see at least 3 things wrong. if (!File.Exists(path)) - path is a Directory, not a File. You want to enter the loop if the directory does exist, not if it doesn't exist. It makes no sense otherwise. path = Filename; - you want to concatenate the two strings to a new variable, not overwrite path. Categories : C# ipad - write NSString to text file this worked for me //Method writes a string to a text file -(void) writeToTextFile{ //get the documents directory: NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; //make a file name to write the data to using the documents directory: NSString *fileName = [NSString stringWithFormat:@"%@/text.txt", documentsDirectory]; //create content - four lines of text NSString *content = @"Test"; //save content to the documents directory [content writeToFile:fileName atomically:NO encoding:NSStringEncod Categories : IOS Write text file in UCS-2 Little Endian, Java It sounds like you need to write a byte-order mark first, so that your application can detect the encoding. (It's not clear what you mean by "it says" - clearly whatever "it" is can guess that it's UTF-16LE, but less reliably than when you've got the BOM.) So just add: writer.write("uFEFF"); before you write anything else. Categories : Java Write/Read then Save text file Basic4Android There are several ways to do it. The simplest is to add the values to a Map and use File.WriteMap / ReadMap. See this tutorial: http://www.basic4ppc.com/android/forum/threads/6690/#content Categories : Android