| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#11
|
| On Tuesday 26 August 2008 19:33, pk wrote: > On Tuesday 26 August 2008 18:40, Oliver Witt wrote: > >> >>> Ok, so you may probably be able to do something like >>> >>> sed -n ' >> >> It's getting awfully close to what I need. I did not think of the "q" >> command. But I believe the addresses mean something else then I need. >> It seems to be returning all line numbers from line >> until the search pattern is matched, but due to the "q", this always >> stops after the first line, thus always giving me > > Make sure you are specifying the -n switch, and, for testing, try removing > the "q". Which port of sed for windows are you using? No, of course my command is wrong, sorry. Try this: sed -n ' (hoping your sed supports the nested construct) |
|
#12
|
| At 2008-08-26 12:40PM, "Oliver Witt" wrote: > > > Ok, so you may probably be able to do something like > > > > sed -n ' > > It's getting awfully close to what I need. I did not think of the "q" > command. But I believe the addresses mean something else then I need. > It seems to be returning all line numbers from line > until the search pattern is matched, but due to the "q", this always > stops after the first line, thus always giving me How about: sed -n '0, -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous |
|
#13
|
| At 2008-08-26 12:40PM, "Oliver Witt" wrote: > > > Ok, so you may probably be able to do something like > > > > sed -n ' > > It's getting awfully close to what I need. I did not think of the "q" > command. But I believe the addresses mean something else then I need. > It seems to be returning all line numbers from line > until the search pattern is matched, but due to the "q", this always > stops after the first line, thus always giving me How about: sed -n '0, I'll echo the sentiment that it's too bad you chose sed instead of awk. -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous |
|
#14
|
| > No, of course my command is wrong, sorry. Try this: > > sed -n ' > > (hoping your sed supports the nested construct) THANK YOU. That is exactly what I needed. |
|
#15
|
| > Only use sed for simple substitutions on a single line. For anything else use > awk, perl, etc.: > > awk -v line=3 -v pattern="the" 'NR>=line && $0~pattern{print; exit}' file > > You may not need your C++ wrapper if you do it all in awk (or vice-versa). Hm, I might do that next time, but for now sed seems to be doing what I need. But you are right, it seems like it would be hard to extend my current program for future purposes. Oliver |
|
#16
|
| > How about: > > * * sed -n '0, That looks like a possibility as well, however, the file might contain millions of lines. That is why I chose sed, because I thought it would be able to do things the most efficient. And this does not look particularly efficient, but I might be wrong about that. |
|
#17
|
| On Tuesday 26 August 2008 19:47, Oliver Witt wrote: >> No, of course my command is wrong, sorry. Try this: >> >> sed -n ' >> >> (hoping your sed supports the nested construct) > > THANK YOU. That is exactly what I needed. You're welcome. If you have GNU sed, Glenn Jackman's solution will work fine too. |
|
#18
|
| On Tuesday 26 August 2008 19:50, Oliver Witt wrote: >> How about: >> >> sed -n '0, > > That looks like a possibility as well, however, the file might contain > millions of lines. That is why I chose sed, because I thought it would > be able to do things the most efficient. And this does not look > particularly efficient, but I might be wrong about that. Well, in all cases sed still has to read each time at least all the lines from line 1 to the line that produces the first match after line guess. But you could of course open the file from your C++ program, and read it line by line and do pattern matching using C++ code (which would however be an OT here). |
![]() |
| Thread Tools | |
| Display Modes | |