PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > beginners sed question inserting file into another file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

beginners sed question inserting file into another file

Réponse
 
LinkBack Outils de la discussion
Vieux 15/07/2007, 18h32   #1
edexter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut beginners sed question inserting file into another file

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.

  Réponse avec citation
Vieux 15/07/2007, 21h54   #2
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: beginners sed question inserting file into another file

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.
  Réponse avec citation
Vieux 16/07/2007, 08h44   #3
edexter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: beginners sed question inserting file into another file

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

  Réponse avec citation
Vieux 16/07/2007, 11h44   #4
edexter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: beginners sed question inserting file into another file

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

  Réponse avec citation
Vieux 16/07/2007, 16h04   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: beginners sed question inserting file into another file

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
  Réponse avec citation
Vieux 17/07/2007, 00h49   #6
edexter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: beginners sed question inserting file into another file

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

  Réponse avec citation
Vieux 17/07/2007, 05h50   #7
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: beginners sed question inserting file into another file

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h29.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15717 seconds with 15 queries