sed help
Hi all
As far as I'v seen sed depends on a line number or a constant in the file, ie changing line 1 or changing 123 to 321. Is it possible to change a variable if you have another constant in a line as in: changing 'this is somenumber' to 'this is anothernumber' if you don't know what the line or variable is. Should I be using sed or is there something better/easer? |
Hi,
You can use 'search ranges' instead of (or combining with) line numbers. I.e.: sed -n '/foo/,/bar/p' infile will print all between the first line with foo (included) and the last line with bar (also included). You can combine real linenumbers with searchstrings: sed -n '2,/foobar/p' infile will print from line 2 to the last line containing foobar. Sed also accepts variables (which could be set and reset in a script for example): THREE="3" sed -n "$THREE,4p" infile The above will print lines 3 and 4. Do mind the double quotes instead of the single quotes. Hope this helps. |
Quote:
Here is the best SED tutorial I have seen: http://www.grymoire.com/Unix/Sed.html I suggest you post an example (excerpt) of a file that you want to process, and the kind of change you want to make. |
All times are GMT -5. The time now is 06:11 PM. |