Questions tagged [line-processing]
13 questions
37
votes
5 answers
How do I iterate over cin line by line in C++?
I want to iterate over std::cin, line by line, addressing each line as a std::string. Which is better:
string line;
while (getline(cin, line))
{
// process line
}
or
for (string line; getline(cin, line); )
{
// process line
}
? What is…

cppLearner
- 371
- 1
- 4
- 3
7
votes
4 answers
Perl - Find duplicate lines in file or array
I'm trying to print duplicate lines from the filehandle, not remove them or anything else I see asked on other questions. I don't have enough experience with perl to be able to quickly do this, so I'm asking here. What's the way to do this?

Chris
- 2,341
- 5
- 23
- 21
5
votes
5 answers
Get random lines from large files in bash
How can I get n random lines from very large files that can't fit in memory.
Also it would be great if I could add filters before or after the randomization.
update 1
in my case the specs are :
> 100 million lines
> 10GB files
usual random batch…

Stefan Rogin
- 1,499
- 3
- 25
- 41
3
votes
4 answers
Extracting specific lines with Perl
I am writing a perl program to extract lines that are in between the two patterns i am matching. for example the below text file has 6 lines. I am matching load balancer and end. I want to get the 4 lines that are in between.
**load balancer**
new…

abhiram potluri
- 45
- 3
- 7
2
votes
5 answers
Split line with perl
title: Football team: Real Madrid stadium: Santiago Bernabeu players: Zinédine Zidane, Ronaldo, Luís Figo, Roberto Carlos, Raúl personnel: José Mourinho (head coach) Aitor Karanka (assistant coach (es))
How to split this with perl in:
title:…

user935420
- 113
- 1
- 7
2
votes
1 answer
Token and line processing Java
I'm writing a program that reads data from a text file with various basketball sports statistics. Each line (after the two header lines) corresponds to one particular game and the scores of each team, with some other strings in there. I'm trying to…

Hector
- 51
- 7
1
vote
0 answers
ImportError "text_process" Python library
I'm taking a look at some CBOW Python implementations.
The owner of the code used a function called "line_processing" from text_process lib.
When I tried to run, I got that error:
ImportError: cannot import name 'line_processing' from…

leob
- 23
- 4
0
votes
3 answers
How to get the particular index from the table stored in a file
I am taking the output from a file in tabular form.
This is how the file.txt will look like. suppose its a 4*4 matrix
1 2 3 4
a b c d
e f g h
i j k l
Now i want to fetch a particular element of the table say 2nd row and 3rd column. I am using the…

Nitesh
- 157
- 10
0
votes
3 answers
Parsing in Java with C style?
I am new to java text parsing and I'm wondering what is the best way to parse a file when the format of each line is known.
I have a file that has the following format for each…

user597608
- 387
- 8
- 20
0
votes
1 answer
Scanner/Token error java
I'm writing a program that reads sports data from a text file. Each line has strings and ints mixed together, and I'm trying to read just the scores of the teams. However, even though the lines have ints, the program immediately goes to the else…

Hector
- 51
- 7
-2
votes
3 answers
Insert new line between two lines with perl
I want to insert line beetwen line 2 and line 3 that contain concatenate string from this lines
abc
abcd:
abc
abcd
Output:
abc
abcd:
abcd: abcd
abc
abcd

Geo Grigore
- 39
- 2
-2
votes
3 answers
Sort Multiple line according to fields
I have a record here with multiple lines, what I what to do is sort them according to type and the 6digits number in the line HEADER1.
Here is the record:
HEADER1|TYPE1|123456|JOHN…

Soncire
- 309
- 1
- 5
- 15
-2
votes
2 answers
Python Detect Missing Line in a Txt File
Let us say a txt file consists of these lines:
A
1
2
3
B
1
2
3
C
1
3
Clearly, 2 is missing from C in the txt file. What is the idea to detect the missing 2 and output it? I need to read the txt file line by line.
Thank you !

Poker Prof
- 169
- 5
- 15