Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output specific line huge text file

Tags:

text

bash

I have a sql dump with 300mb that gives me an error on specific line.

But that line is in the middle of the file. What is the best approach?

head -n middleLine dump.sql > output?

Or can i output only the line i need?

like image 764
balsagoth Avatar asked Nov 17 '11 11:11

balsagoth


People also ask

Which command is used to extract specific lines records from a file?

awk. sed. "head+tail"

How do I extract a specific line from a file in Python?

You can use an index number as a line number to extract a set of lines from it. This is the most straightforward way to read a specific line from a file in Python. We read the entire file using this way and then pick specific lines from it as per our requirement.

Which command is best to print just the first line from a huge file?

The default command which comes to our mind is the head command. head with the option "-1" displays the first line. 2. The best of all options since it uses an internal command.


2 Answers

You could use sed -n -e 123456p your.dump to print line 123456

like image 74
Basile Starynkevitch Avatar answered Sep 19 '22 03:09

Basile Starynkevitch


If the file is long, consider using

sed -n 'X{p;q}' file 

Where X is the line number. It will stop reading the file after reaching that line.

like image 30
ata Avatar answered Sep 20 '22 03:09

ata