Reputation: 2219
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?
Upvotes: 49
Views: 47196
Reputation: 242
This can also be done with Perl:
perl -wnl -e '$. == 4444444 and print and exit;' FILENAME.sql
4444444 being the line number you wish to print.
Upvotes: 3
Reputation: 420
You can also try awk
like:
awk 'NR==YOUR_LINE_NO{print}' file_name
Upvotes: 2
Reputation: 623
If sed
is too slow for your taste you may also use
cat $THE_FILE | head -n $DESIRED_LINE | tail -n 1
Upvotes: 10
Reputation: 58371
This might work for you:
sed 'X!d;q' file
where X is the line number.
Upvotes: 3
Reputation: 2065
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.
Upvotes: 25
Reputation: 1434
If you know a phrase on that line I would use grep
. If the phrase is "errortext" use:
$ cat dump.sql | grep "errortext"
Upvotes: -4
Reputation: 1
You could use sed -n -e 123456p your.dump
to print line 123456
Upvotes: 63
Reputation: 149736
You can use sed:
sed -n "x p" dump.sql
where x
is the line number.
Upvotes: 4