|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
sed -e '/[;<instr1]' -e '/[;<endin>]/{r strings.orc}' bay-at-
night.csd I am trying to do two searchs for a string and then insert strings.orc into a file called bay-at-night.csd It sorta looks scrambeled on my dos prompt and I figure I may be close but am making a simple mistake. I was having trouble finding examples of this online and I am just looking for the best way to do this (I have the gnu port but don't know that much about unix and the shells) so if there is a better unix way I would be intrested in that also. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Sun, 15 Jul 2007 10:32:28 -0700, edexter wrote:
> sed -e '/[;<instr1]' -e '/[;<endin>]/{r strings.orc}' bay-at- night.csd > > I am trying to do two searchs for a string and then insert strings.orc > into a file called bay-at-night.csd It sorta looks scrambeled on my dos > prompt and I figure I may be close but am making a simple mistake. I > was having trouble finding examples of this online and I am just looking > for the best way to do this (I have the gnu port but don't know that > much about unix and the shells) so if there is a better unix way I would > be intrested in that also. I am not sure that we understand what you mean by "do two searches". Sed works by applying its commands to each input line. It is not like "ed", which has the concept of the current position in the file. Can you give us a few sentence description of what you would like to do, as precisely as possible, and we can work from that. It is also not clear from your example if you know that the "[" and "]" characters are special to sed, and mean match any of the characters listed between them. Finally, "looking scrambeled in dos" is a common problem due to different line ending conventions. Without knowing in what manner the output is scrambled it is hard to know if we can tell you this is harmless or not. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Jul 15, 3:54 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
> On Sun, 15 Jul 2007 10:32:28 -0700, edexter wrote: > > sed -e '/[;<instr1]' -e '/[;<endin>]/{r strings.orc}' bay-at- night.csd > > > I am trying to do two searchs for a string and then insert strings.orc > > into a file called bay-at-night.csd It sorta looks scrambeled on my dos > > prompt and I figure I may be close but am making a simple mistake. I > > was having trouble finding examples of this online and I am just looking > > for the best way to do this (I have the gnu port but don't know that > > much about unix and the shells) so if there is a better unix way I would > > be intrested in that also. > > I am not sure that we understand what you mean by "do two searches". Sed > works by applying its commands to each input line. It is not like "ed", > which has the concept of the current position in the file. > > Can you give us a few sentence description of what you would like to do, > as precisely as possible, and we can work from that. > > It is also not clear from your example if you know that the "[" and "]" > characters are special to sed, and mean match any of the characters > listed between them. > > Finally, "looking scrambeled in dos" is a common problem due to different > line ending conventions. Without knowing in what manner the output is > scrambled it is hard to know if we can tell you this is harmless or not. I need to do one search for ;<instr> after that one search for ;<endin> after that my curser (hopefully is in the right position after the word ;<endin>) I need to load in the file strings.orc into the file bay-at-night.csd. I am going to be using popen to use this script after I have it debugged |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Jul 15, 3:54 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
> On Sun, 15 Jul 2007 10:32:28 -0700, edexter wrote: > > sed -e '/[;<instr1]' -e '/[;<endin>]/{r strings.orc}' bay-at- night.csd > > > I am trying to do two searchs for a string and then insert strings.orc > > into a file called bay-at-night.csd It sorta looks scrambeled on my dos > > prompt and I figure I may be close but am making a simple mistake. I > > was having trouble finding examples of this online and I am just looking > > for the best way to do this (I have the gnu port but don't know that > > much about unix and the shells) so if there is a better unix way I would > > be intrested in that also. > > I am not sure that we understand what you mean by "do two searches". Sed > works by applying its commands to each input line. It is not like "ed", > which has the concept of the current position in the file. > > Can you give us a few sentence description of what you would like to do, > as precisely as possible, and we can work from that. > > It is also not clear from your example if you know that the "[" and "]" > characters are special to sed, and mean match any of the characters > listed between them. > > Finally, "looking scrambeled in dos" is a common problem due to different > line ending conventions. Without knowing in what manner the output is > scrambled it is hard to know if we can tell you this is harmless or not. sed -e '/[;<instr1>]' -e '/[endin]{r c:\dex_tracker\strings.orc}' c: \dex_tracker\bay-at-night.csd pause when I change it to this it tells me that it cannot find the file specified. all the files including sed are in c:\dex_tracker |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Mon, 16 Jul 2007 03:44:17 -0700, edexter
<Eric_Dexter@msn.com> wrote: > > > > sed -e '/[;<instr1>]' -e '/[endin]{r c:\dex_tracker\strings.orc}' c: > \dex_tracker\bay-at-night.csd > pause > > when I change it to this it tells me that it cannot find the file > specified. all the files including sed are in c:\dex_tracker > You might have to use forward slashes or double backslashes in the filenames. -- In good speaking, should not the mind of the speaker know the truth of the matter about which he is to speak? -- Plato |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Jul 16, 10:04 am, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On Mon, 16 Jul 2007 03:44:17 -0700, edexter <Eric_Dex...@msn.com> wrote: > > > sed -e '/[;<instr1>]' -e '/[endin]{r c:\dex_tracker\strings.orc}' c: > > \dex_tracker\bay-at-night.csd > > pause > > > when I change it to this it tells me that it cannot find the file > > specified. all the files including sed are in c:\dex_tracker > > You might have to use forward slashes or double backslashes in the > filenames. > > -- > In good speaking, should not the mind of the speaker know the truth of > the matter about which he is to speak? > -- Plato thanks I will give that a shot |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Mon, 16 Jul 2007 00:44:16 -0700, edexter wrote:
> On Jul 15, 3:54 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote: >> On Sun, 15 Jul 2007 10:32:28 -0700, edexter wrote: >> > sed -e '/[;<instr1]' -e '/[;<endin>]/{r strings.orc}' bay-at- >> > night.csd >> >> > I am trying to do two searchs for a string and then insert >> > strings.orc into a file called bay-at-night.csd It sorta looks >> > scrambeled on my dos prompt and I figure I may be close but am making >> > a simple mistake. I was having trouble finding examples of this >> > online and I am just looking for the best way to do this (I have the >> > gnu port but don't know that much about unix and the shells) so if >> > there is a better unix way I would be intrested in that also. >> >> I am not sure that we understand what you mean by "do two searches". >> Sed works by applying its commands to each input line. It is not like >> "ed", which has the concept of the current position in the file. >> >> Can you give us a few sentence description of what you would like to >> do, as precisely as possible, and we can work from that. >> >> It is also not clear from your example if you know that the "[" and "]" >> characters are special to sed, and mean match any of the characters >> listed between them. >> >> Finally, "looking scrambeled in dos" is a common problem due to >> different line ending conventions. Without knowing in what manner the >> output is scrambled it is hard to know if we can tell you this is >> harmless or not. > > I need to do one search for ;<instr> after that one search for ;<endin> > after that my curser (hopefully is in the right position after the word > ;<endin>) I need to load in the file strings.orc into the file > bay-at-night.csd. I am going to be using popen to use this script after > I have it debugged This is not easy. The problem is the line oriented nature of sed. If you know how many lines there are in strings.orc (and I am guessing it is probably 1), then I would do it as follows. As this is complicated, I would put the sed instructions into a file, and invoke it as follows sed -f sedcmds strings.orc bay-at-night.csd The contents of the sedcmds file would be # adjust the 2 in the following to be the number of lines # in the strings.orc file. If there is only 1 then change # it to 1{, rather than 1,1{ 1,2{ H d } # We now have the new text in the hold space # We now skip over the lines until we find the ;<instr> 1,/;<instr>/{ p d } # We now look for the ;<endin> /;<endin>/{ # We get the text we want to insert firstly onto the end of the line G # Now we swap the parts of the line around s/\(;<endin>\)\([^\n]*\)\n\n\(.*\)/\1\3\2/ } If the strings.orc file has an unknown number of lines, but has a distinctive last line, then this can be used. I suggest that sed is probably not the right tool for this particular job, that awk or perl (or ruby or python or tcl or basic or almost anything) would be better. |
|
![]() |
| Outils de la discussion | |
|
|