text-files

batch: replace a line in a text file

狂风中的少年 提交于 2019-12-03 04:07:12
I'm trying to replace this line: # forward-socks5 / 127.0.0.1:9050 . with this one: forward-socks5 / 127.0.0.1:9050 . this line belongs to a config file that has to be enabled (UN-commented) by deleting the # sign from the beginning and I could not thought of a better way other than replacing the line with another without the # sign. any other thoughts or ways would be very useful. btw, the spaces before the text are there also. I have pasted the text as it was in the original file. thanks in advance EDIT: I have somehow managed to do the line addition and removing using two peaces of code

Batch replace text inside text file (Linux/OSX Commandline)

时光毁灭记忆、已成空白 提交于 2019-12-03 03:55:14
I have hundreds of files where I need to change a portion of its text. For example, I want to replace every instance of "http://" with "rtmp://" . The files have the .txt extention and are spread across several folders and subfolder. I basically am looking for a way/script that goes trough every single folder/subfolder and every single file and if it finds inside that file the occurrence of "http" to replace it with "rtmp". You can do this with a combination of find and sed : find . -type f -name \*.txt -exec sed -i.bak 's|http://|rtmp://|g' {} + This will create backups of each file. I

Notepad++: Capitalize first letter by Shortcut?

点点圈 提交于 2019-12-03 03:45:37
问题 I've got a huge list of words (every single word in one line in a txt file) and certain words need to get capitalized manually (e.g. by hand), so I was looking if there's a shortcut in notepad++ (my editor currently) to automatically capitalize the first letter of a line but couldnt find one. Is there none? If not, can you advise me an alternative windows program to quickly do this by using a simple shortcut (so I can go through with the arrow-down key and use the shortcut whenever needed on

How can I write strings and matrices to a .txt file in MATLAB?

时间秒杀一切 提交于 2019-12-03 02:59:08
I need to write data to a .txt file in MATLAB. I know how to write strings ( fprintf ) or matrices ( dlmwrite ), but I need something that can do both of them. I'll give an example below: str = 'This is the matrix: ' ; mat1 = [23 46 ; 56 67] ; %fName if *fid is valid* fprintf(fid, '%s\n', str) fclose(fid) end dlmwrite(fName, *emptymatrix*, '-append', 'delimiter', '\t', 'newline','pc') dlmwrite(fName, mat1, '-append', 'newline', 'pc') This works okay, but with a problem. The first line of the file is: This is the matrix: 23,46 Which is not what I want. I want to see: This is the matrix: 23 46

PHP library for creating/manipulating fixed-width text files

我怕爱的太早我们不能终老 提交于 2019-12-03 02:45:28
We have a web application that does time-tracking, payroll, and HR. As a result, we have to write a lot of fixed-width data files for export into other systems (state tax filings, ACH files, etc). Does anyone know of a good library for this where you can define the record types/structures, and then act on them in an OOP paradigm? The idea would be a class that you hand specifications, and then work with an instance of said specification. IE: $icesa_file = new FixedWidthFile(); $icesa_file->setSpecification('icesa.xml'); $icesa_file->addEmployer( $some_data_structure ); Where icesa.xml is a

I Need a Human Readable, Yet Parse-able Document Format

旧时模样 提交于 2019-12-03 01:41:46
I'm working on one of those projects where there are a million better ways to accomplish what I need but I have no choice and I have to do it this way. Here it is: There is a web form, when the user fills it out and hits a submit a human readable text file is created using the form data. It looks like this: field_1: value for field one field_2: value for field two more data for field two (field two has a newline in it!) field3: some more data My problem is this: I need to parse this text file back into the web form so that the user can edit it. How could I, in a foolproof way, accomplish this?

A pythonic way to insert a space before capital letters

邮差的信 提交于 2019-12-03 00:01:17
I've got a file whose format I'm altering via a python script. I have several camel cased strings in this file where I just want to insert a single space before the capital letter - so "WordWordWord" becomes "Word Word Word". My limited regex experience just stalled out on me - can someone think of a decent regex to do this, or (better yet) is there a more pythonic way to do this that I'm missing? You could try: >>> re.sub(r"(\w)([A-Z])", r"\1 \2", "WordWordWord") 'Word Word Word' If there are consecutive capitals, then Gregs result could not be what you look for, since the \w consumes the

Proper Java classes for reading and writing files?

我只是一个虾纸丫 提交于 2019-12-02 23:53:26
Reading some sources about Java file I/O managing, I get to know that there are more than 1 alternative for input and output operations. These are: BufferedReader and BufferedWriter FileReader and FileWriter FileInputStream and FileOutputStream InputStreamReader and OutputStreamWriter Scanner class What of these is best alternative for text files managing? What's best alternative for serialization? What does Java NIO say about it? Two kinds of data Generally speaking there are two "worlds": binary data text data When it's a file (or a socket, or a BLOB in a DB, or ...), then it's always binary

How to read data from files in Turbo c++ 4.0?

血红的双手。 提交于 2019-12-02 23:31:46
问题 I am a beginner in programming and I am trying to make a code that reads 2 numbers from a file and then displays it in the output window on turbo c++. My code only reads the first number and produces incorrect output for the second number. #include<iostream.h> #include<fstream.h> #include<conio.h> void main() { int x, y; clrscr(); ifstream inFile; ofstream outFile; inFile.open("prac.txt"); while(!inFile.eof()) inFile >> x >> y; cout << x << " " << y; inFile.close(); } The file contains the

Text file with ^M on each line

别等时光非礼了梦想. 提交于 2019-12-02 22:52:41
I just got a source code file from a friend. The file was created in UNIX. When I opened it in Windows using NotePad++, each line had one extra blank line. Puzzled, I downloaded Vim and used it to open the file. I then saw a bunch of ^M at the end of each line. What is this ^M? How do you prevent it from being inserted? Those are DOS/Windows-style line-endings (to be pedantic that's what they're commonly known as now but most early non-UNIX OSes like CP/M and OS/2 had them as well). On the various Unices, line-endings are \n . In DOS/Windows the line-endings are \r\n (CR+LF or Carriage-Return