txt is the conventional filename extension of text files.
Questions tagged [txt]
1467 questions
2
votes
2 answers
Reading a txt file into a list without newlines in python
I have a txt file that looks like this:
FSDAF
HKLWF
AAKEP
How can I read that into a list so it looks like this:
lst = ['FSDAF', 'HKLWF', 'AAKEP']
I did something like this but I cant get rid of the newlines:
file = open('dane.txt', 'r')
lst…

low_ratio
- 51
- 5
2
votes
2 answers
split a txt file into multiple files with the number of lines in each file being able to be set by a user
I'm writing something in C# and I need to find a way to split a text file into more files with the number of lines in the file being equivalent to a user input.
Example : file a had 1000 lines in it and I want the code to ask the user for a number…

izakvh
- 23
- 6
2
votes
4 answers
Extract line of text from .txt file using CMD?
was wandering if there is a way to extract a line of text which contains certain value from a .txt file using CMD. For example using "type filepath\example.txt" will open the whole file and in my case I am working trough a software which doesn't…

milke 92
- 39
- 1
- 5
2
votes
1 answer
R read.table error: line 1 did not have 52 elements
I am trying to read weather data from the German Weather Service (DWD). Here is a small portion of the .txt-File:
KL02222200001010000101061101131101471101224 661 321 344 30 1 411 551 571 524 34 6 55 6 56 6 734 904 904 844 8941004 994 964…

Lukas D. Sauer
- 355
- 2
- 11
2
votes
1 answer
Python code to extract txt from PDF document
I have been trying to convert some PDFs into .txt, but most sample codes I found online have the same issue: They only convert one page at a time. I am kinda new to python, and I am not finding how to write a substitute for the .GetPage() method to…
2
votes
4 answers
Adding a comma between JSON objects in a datafile with Python?
I have large file (about 3GB) which contains what looks like a JSON file but isn't because it lacks commas (,) between "observations" or JSON objects (I have about 2 million of these "objects" in my data file).
For example, this is what I have:
{
…

Essan Rago
- 77
- 1
- 5
2
votes
3 answers
How to make a dictionary from a txt file?
Assuming a following text file (dict.txt) has
1 2 3
aaa bbb ccc
the dictionary should be {1: aaa, 2: bbb, 3: ccc} like this
I did:
d = {}
with open("dict.txt") as f:
for line in f:
(key, val) = line.split()
d[int(key)] = val
print…

mustafa789
- 39
- 1
- 4
2
votes
2 answers
Omitting the final end-of-line character for txt file (write.table in R)
I have a simple data.frame that I would like to write to an output .txt file using R.
Sample code:
my_df <- data.frame(name = c("Wendy", "Quinn"), age = c(23, 43))
write.table(my_df, file = "my_output_file.txt", sep = " ", col.names = F, row.names =…
2
votes
1 answer
convert a txt data file to structured JSON using PHP
I have one large plain text file which its data is like this:
65781>foo-98503>bar-12783>baz-71284>foobar
I want to convert it to JSON format so the content should be a valid JSON:
{
"65781":"foo",
"98503":"bar",
"12783":"baz",
…

user17348055
- 23
- 3
2
votes
2 answers
JetBrains IDE make link clickable in .txt files
I am opening a .txt file with my PyCharm IDE that contains multiple links among several other lines of text (actually these are logs from a continuously running script).
Like so:
----------------------- session start, Tuesday 12.10.2021,…

Simon Mayrshofer
- 1,264
- 1
- 11
- 18
2
votes
4 answers
How do I sort numbers from a text file using Java?
I have tried multiple solutions suggested by other threads on StackOverflow, but I haven't found a solution. I'm trying to read a .txt file and sort the content from largest to smallest, using Java. This is what my .txt file contains:
16° C
15°…

virreoh
- 21
- 3
2
votes
2 answers
How to join all the txt files that are inside a directory? (Respecting that all lines are one below the other)
I use this code to list all those txt that are in the directory of the indicated path
from glob import glob
path_directory = 'Part001/*.txt'
list_files = glob(path_directory)
for f in list_files:
print(f)
I need help to be able to merge all…
user15898019
2
votes
2 answers
comparing two .txt, difflib module tells me that a line is unique ('-') when in fact it is present in both .txt
I need help with difflib module.
I'm using difflib (https://docs.python.org/3/library/difflib.html) to compare 2 txt from url, line by line, and find duplications and missing lines. difflib flag with a '-' each line that it's only unique in one of…

Sebastian
- 27
- 3
2
votes
1 answer
txt file with integers, strings and bulleted list (1.)
I have a txt file which has several rows like this
7. SSWAB 38 15 - 57
but I don't need all the values, just the String and the integers.
I would use nextInt for the Integers, but how can I deal with 1. and -?
Also there is the…

redbite
- 189
- 1
- 2
- 10
2
votes
2 answers
Server http displays a variable from .txt with python
I would like to make a HTTP request (PYTHON) with a web server that displays a data from a .txt file.
I have this data1.txt file that contains:
bonjour
and here is my code webserver.py:
#!/usr/bin/python
from http.server import…

Camille BOUQUET
- 445
- 1
- 6
- 18