Questions tagged [text-files]

The TXT file type is primarily associated with 'Text File'. Open in Notepad, WordPad, or many other programs designated as text editors. A true text file will be pure ASCII text with no formatting.

6722 questions
53
votes
2 answers

Embed Text File in a Resource in a native Windows Application

I have a C++ Windows program. I have a text file that has some data. Currently, the text file is a separate file, and it is loaded at runtime and parsed. How is it possible to embed this into the binary as a resource?
Oliver Zheng
  • 7,831
  • 8
  • 53
  • 59
51
votes
5 answers

Remove Unicode characters from textfiles - sed , other Bash/shell methods

How do I remove Unicode characters from a bunch of text files in the terminal? I've tried this, but it didn't work: sed 'g/\u'U+200E'//' -i *.txt I need to remove these Unicode characters from the text files: U+0091 - sort of weird "control"…
alvas
  • 115,346
  • 109
  • 446
  • 738
51
votes
2 answers

Performance effect of using print statements in Python script

I have a Python script that process a huge text file (with around 4 millon lines) and writes the data into two separate files. I have added a print statement, which outputs a string for every line for debugging. I want to know how bad it could be…
Sudar
  • 18,954
  • 30
  • 85
  • 131
50
votes
4 answers

How to efficiently write a large text file in C#?

I am creating a method in C# which generates a text file for a Google Product Feed. The feed will contain upwards of 30,000 records and the text file currently weighs in at ~7Mb. Here's the code I am currently using (some lines removed for brevity's…
jessegavin
  • 74,067
  • 28
  • 136
  • 164
50
votes
6 answers

Where is hex code of the "EOF" character?

As far as know in the end of all files, specially text files, there is a Hex code for EOF or NULL character. And when we want to write a program and read the contents of a text file, we send the read function until we receive that EOF hexcode. My…
user3739941
49
votes
3 answers

How do I pair every two lines of a text file with Bash?

With a simple bash script I generate a text file with many lines like this: 192.168.1.1 hostname1 192.168.1.2 hostname2 192.168.1.3 hostname3 Now I want to reformat this file so it looks like this: 192.168.1.1 hostname1 192.168.1.2…
fwaechter
  • 885
  • 3
  • 10
  • 19
48
votes
7 answers

Count number of blank lines in a file

In count (non-blank) lines-of-code in bash they explain how to count the number of non-empty lines. But is there a way to count the number of blank lines in a file? By blank line I also mean lines that have spaces in them.
Sudar
  • 18,954
  • 30
  • 85
  • 131
47
votes
2 answers

Easiest way to read text file which is locked by another application

I've been using File.ReadAllText() to open a CSV file, but every time I forget to close the file in Excel, the application throws an exception because it can't get access to the file. (Seems crazy to me, I mean the READ in ReadAllText seems pretty…
Benjol
  • 63,995
  • 54
  • 186
  • 268
46
votes
9 answers

How to read a text file directly from Internet using Java?

I am trying to read some words from an online text file. I tried doing something like this File file = new File("http://www.puzzlers.org/pub/wordlists/pocket.txt"); Scanner scan = new Scanner(file); but it didn't work, I am getting…
randomizertech
  • 2,309
  • 15
  • 48
  • 85
45
votes
4 answers

How to read text file in react

Screenshot1 Screenshot2 I want to read from a text file within the react project, but when I try to execute and read I get a HTML sample code in the console log. This is the function: onclick= () =>{ fetch('data.txt') .then(function(response){ …
Salvadore Rina
  • 559
  • 1
  • 4
  • 7
43
votes
13 answers

remove empty lines from text file with PowerShell

I know that I can use: gc c:\FileWithEmptyLines.txt | where {$_ -ne ""} > c:\FileWithNoEmptyLines.txt to remove empty lines. But How I can remove them with '-replace' ?
Suliman
  • 1,469
  • 3
  • 13
  • 19
42
votes
7 answers

Easiest way to add a text to the beginning of another text file in Command Line (Windows)

What is the easiest way to add a text to the beginning of another text file in Command Line (Windows)?
dr. evil
  • 26,944
  • 33
  • 131
  • 201
42
votes
7 answers

Copying from one text file to another using Python

I would like to copy certain lines of text from one text file to another. In my current script when I search for a string it copies everything afterwards, how can I copy just a certain part of the text? E.g. only copy lines when it has…
DevCon
  • 569
  • 1
  • 6
  • 15
42
votes
4 answers

Python Multiple users append to the same file at the same time

I'm working on a python script that will be accessed via the web, so there will be multiple users trying to append to the same file at the same time. My worry is that this might cause a race condition where if multiple users wrote to the same file…
Ray Y
  • 1,261
  • 3
  • 16
  • 24
38
votes
6 answers

How to read plain text file in kotlin?

There may be various way to read plain text file in kotlin. I want know what are the possible ways and how I can use them.
Anisuzzaman Babla
  • 6,510
  • 7
  • 36
  • 53