Editing a specific group of lines by line number?
I have a 4GB database dump that I need to edit. Loading this file in an editor like pico would be agonizingly slow obviously - is there any way to edit set of a few lines (say 20, starting with line number 10000) by line number? Perhaps using the sed command.
Also how might one display a specified number of lines, starting with a given line number (again, say 20 lines starting at 10000). I tried Code:
sed -l 20 -n '46810p' filename.sql |
The "-l 20" syntax sets the line wrap length for the "l" command. How is that relevant to your goal?
Why not an address range? For example, to print 20 lines starting with #10000: sed -n '10000,10019p' OR--in Gnu sed: sed -n '10000,+19p' http://www.gnu.org/software/sed/manual/sed.html (Gnu sed--a few extra features) http://www.grymoire.com/Unix/Sed.html (generic sed---the BEST tutorial ever) |
Thank you very much!
Quote:
So would editing the selected lines in the file consist of something like this? Code:
sed -n '10000,+19p s/orig/new' filename.sql 1) I originally thought this was an editor where you could specify a set of lines and then edit them by hand, but I think that one has to use the substitute command. Yet, when I do something like Code:
sed -n '10000,+19p' filename.sql 2) Can one print line numbers before the output? |
You will find most of this in the links I gave you..
For example, this will not work: Code:
sed -n '10000,+19p s/orig/new' [flags] [address] command within this, some commands allow additional commands to be added "where they make sense". These are legal: Code:
sed -n '10000,+19s/orig/new/' Quote:
Code:
sed -n '{2,6p;7q}' Quote:
|
Thanks again. Those links have a lot to read, very easy to miss stuff :) Even when I see what I need it's pretty confusing.
I'm having a lot of trouble getting line numbers to work. No matter where I place the '=' within the pattern, I get an "extra characters after command" error. With something like: Code:
sed -n '{2,6p;7q}' dump.sql |
try these:
sed = filename sed -n = filename Note that combining commands usually requires { ; } (as in one of my examples) |
All times are GMT -5. The time now is 09:33 PM. |