Loading ...
Sorry, an error occurred while loading the content.
 

RE: [BATCH WORLD] SED Question

Expand Messages
  • Morris, Lamar
    Thanks Mic. BTW both examples are having a problem with c: a.txt if I understand what you re doing (don t laugh too hard) your directing the ini file in to the
    Message 1 of 27 , Jul 25, 2007
      Thanks Mic. BTW both examples are having a problem with c:\a.txt



      if I understand what you're doing (don't laugh too hard) your directing
      the ini file in to the SED statement then piping the results out to a
      file named a.txt then piping it back to the ini file.



      Lamar



      ________________________________

      From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
      Behalf Of foxidrive
      Sent: Wednesday, July 25, 2007 11:47 AM
      To: batchworld@yahoogroups.com
      Subject: Re: [BATCH WORLD] SED Question



      On Thu, 26 Jul 2007 02:30:18 +1000, foxidrive <foxidrive@...
      <mailto:foxidrive%40nerdshack.com> >
      wrote:

      >On Wed, 25 Jul 2007 11:16:51 -0500, "Morris, Lamar" <LamarMorris@...
      <mailto:LamarMorris%40ti.com> >
      >wrote:
      >
      >>I've been trying to get this to work but haven't had any luck. Any
      help
      >>would be apprecitated.
      >
      >I think this is what you want to do, Lamar.
      >
      >
      >
      >@echo off
      >FOR /F "TOKENS=1" %%i IN (name.txt) DO (
      >sed "s/Reconnect=NO/Reconnect=60/g" <%%i\wyse\wnos\wnos.ini >c:\a.txt
      >move c:\a.txt %%i\wyse\wnos\wnos.ini
      >)
      >del c:\a.txt

      This is meant to change "Reconnect" and any three characters to
      "Reconnect=90" in the first 14 lines. I learned that I can operate on
      just
      a range too so thanks. :) Test it well, of course.

      @echo off
      FOR /F "TOKENS=1" %%i IN (name.txt) DO (
      sed "1,14 s/Reconnect.../Reconnect=90/" <%%i\wyse\wnos\wnos.ini
      >c:\a.txt
      move c:\a.txt %%i\wyse\wnos\wnos.ini
      )
      del c:\a.txt





      [Non-text portions of this message have been removed]
    • foxidrive
      On Wed, 25 Jul 2007 11:52:44 -0500, Morris, Lamar ... What s the error please? It is taking the first token in name.txt (I assumed they
      Message 2 of 27 , Jul 25, 2007
        On Wed, 25 Jul 2007 11:52:44 -0500, "Morris, Lamar" <LamarMorris@...>
        wrote:

        >Thanks Mic. BTW both examples are having a problem with c:\a.txt
        >
        >if I understand what you're doing (don't laugh too hard) your directing
        >the ini file in to the SED statement then piping the results out to a
        >file named a.txt then piping it back to the ini file.

        >@echo off
        >FOR /F "TOKENS=1" %%i IN (name.txt) DO (
        >sed "1,14 s/Reconnect.../Reconnect=90/" <%%i\wyse\wnos\wnos.ini c:\a.txt
        >move c:\a.txt %%i\wyse\wnos\wnos.ini
        >)
        >del c:\a.txt

        What's the error please?

        It is taking the first token in name.txt (I assumed they are server names)
        and then replacing the text in the file on the server and piping the
        changed info to c:\a.txt (That a.txt should be at the end of the line.)

        The next line overwrites the original file on the server with the new data.
      • foxidrive
        On Thu, 26 Jul 2007 03:02:04 +1000, foxidrive ... @echo off FOR /F TOKENS=1 %%i IN (name.txt) DO ( sed 1,14
        Message 3 of 27 , Jul 25, 2007
          On Thu, 26 Jul 2007 03:02:04 +1000, foxidrive <foxidrive@...>
          wrote:

          >On Wed, 25 Jul 2007 11:52:44 -0500, "Morris, Lamar" <LamarMorris@...>
          >wrote:
          >
          >>Thanks Mic. BTW both examples are having a problem with c:\a.txt
          >>
          >>if I understand what you're doing (don't laugh too hard) your directing
          >>the ini file in to the SED statement then piping the results out to a
          >>file named a.txt then piping it back to the ini file.

          @echo off
          FOR /F "TOKENS=1" %%i IN (name.txt) DO (
          sed "1,14 s/Reconnect.../Reconnect=90/" <%%i\wyse\wnos\wnos.ini >c:\a.txt
          move c:\a.txt %%i\wyse\wnos\wnos.ini
          )
          del c:\a.txt

          I see my error, I missed the redirection symbol.
        • Morris, Lamar
          It s still complaining about a.txt it appears that it may be creating the a.txt because I can create one and it will get deleted.
          Message 4 of 27 , Jul 25, 2007
            It's still complaining about a.txt it appears that it may be creating
            the a.txt because I can create one and it will get deleted.



            D:\Batch\Greg\07-25-07\TESTFOLDER>60to90

            Could Not Find c:\a.txt



            I'm assuming that there are 6 lines to the script.



            @echo off
            FOR /F "TOKENS=1" %%i IN (name.txt) DO (
            sed "1,14 s/Reconnect.../Reconnect=90/" <%%i\wyse\wnos\wnos.ini
            >c:\a.txt
            move c:\a.txt %%i\wyse\wnos\wnos.ini
            )
            del c:\a.txt



            Lamar



            ________________________________

            From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
            Behalf Of foxidrive
            Sent: Wednesday, July 25, 2007 12:05 PM
            To: batchworld@yahoogroups.com
            Subject: Re: [BATCH WORLD] SED Question



            On Thu, 26 Jul 2007 03:02:04 +1000, foxidrive <foxidrive@...
            <mailto:foxidrive%40nerdshack.com> >
            wrote:

            >On Wed, 25 Jul 2007 11:52:44 -0500, "Morris, Lamar" <LamarMorris@...
            <mailto:LamarMorris%40ti.com> >
            >wrote:
            >
            >>Thanks Mic. BTW both examples are having a problem with c:\a.txt
            >>
            >>if I understand what you're doing (don't laugh too hard) your
            directing
            >>the ini file in to the SED statement then piping the results out to a
            >>file named a.txt then piping it back to the ini file.

            @echo off
            FOR /F "TOKENS=1" %%i IN (name.txt) DO (
            sed "1,14 s/Reconnect.../Reconnect=90/" <%%i\wyse\wnos\wnos.ini
            >c:\a.txt
            move c:\a.txt %%i\wyse\wnos\wnos.ini
            )
            del c:\a.txt

            I see my error, I missed the redirection symbol.





            [Non-text portions of this message have been removed]
          • foxidrive
            On Wed, 25 Jul 2007 12:10:03 -0500, Morris, Lamar ... 5 lines in total now. I ve changed the script ever so slightly to make wrapping
            Message 5 of 27 , Jul 25, 2007
              On Wed, 25 Jul 2007 12:10:03 -0500, "Morris, Lamar" <LamarMorris@...>
              wrote:

              >It's still complaining about a.txt it appears that it may be creating
              >the a.txt because I can create one and it will get deleted.
              >
              >
              >
              >D:\Batch\Greg\07-25-07\TESTFOLDER>60to90
              >
              >Could Not Find c:\a.txt
              >
              >
              >
              >I'm assuming that there are 6 lines to the script.

              5 lines in total now. I've changed the script ever so slightly to make
              wrapping more obvious.

              @echo off
              FOR /F "TOKENS=1" %%i IN (name.txt) DO (
              sed "1,14 s/Reconnect.../Reconnect=90/" %%i\wyse\wnos\wnos.ini>c:\a.txt
              move c:\a.txt %%i\wyse\wnos\wnos.ini
              )


              The error was the last line (deleted now) that was trying to remove the
              temp file but it no longer existed, because I was using MOVE.
            • Morris, Lamar
              Thanks, Mic it s running without error now and changing the time stamp on the INI files, but it s not making the expected change. Lamar
              Message 6 of 27 , Jul 25, 2007
                Thanks, Mic it's running without error now and changing the time stamp
                on the INI files, but it's not making the expected change.



                Lamar



                ________________________________

                From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
                Behalf Of foxidrive
                Sent: Wednesday, July 25, 2007 12:16 PM
                To: batchworld@yahoogroups.com
                Subject: Re: [BATCH WORLD] SED Question



                On Wed, 25 Jul 2007 12:10:03 -0500, "Morris, Lamar" <LamarMorris@...
                <mailto:LamarMorris%40ti.com> >
                wrote:

                >It's still complaining about a.txt it appears that it may be creating
                >the a.txt because I can create one and it will get deleted.
                >
                >
                >
                >D:\Batch\Greg\07-25-07\TESTFOLDER>60to90
                >
                >Could Not Find c:\a.txt
                >
                >
                >
                >I'm assuming that there are 6 lines to the script.

                5 lines in total now. I've changed the script ever so slightly to make
                wrapping more obvious.

                @echo off
                FOR /F "TOKENS=1" %%i IN (name.txt) DO (
                sed "1,14 s/Reconnect.../Reconnect=90/" %%i\wyse\wnos\wnos.ini>c:\a.txt
                move c:\a.txt %%i\wyse\wnos\wnos.ini
                )

                The error was the last line (deleted now) that was trying to remove the
                temp file but it no longer existed, because I was using MOVE.





                [Non-text portions of this message have been removed]
              • Morris, Lamar
                Mic, can you explain what you re doing here. sed 1,14 Lamar ________________________________ From: batchworld@yahoogroups.com
                Message 7 of 27 , Jul 25, 2007
                  Mic, can you explain what you're doing here.



                  sed "1,14



                  Lamar



                  ________________________________

                  From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
                  Behalf Of foxidrive
                  Sent: Wednesday, July 25, 2007 12:16 PM
                  To: batchworld@yahoogroups.com
                  Subject: Re: [BATCH WORLD] SED Question



                  On Wed, 25 Jul 2007 12:10:03 -0500, "Morris, Lamar" <LamarMorris@...
                  <mailto:LamarMorris%40ti.com> >
                  wrote:

                  >It's still complaining about a.txt it appears that it may be creating
                  >the a.txt because I can create one and it will get deleted.
                  >
                  >
                  >
                  >D:\Batch\Greg\07-25-07\TESTFOLDER>60to90
                  >
                  >Could Not Find c:\a.txt
                  >
                  >
                  >
                  >I'm assuming that there are 6 lines to the script.

                  5 lines in total now. I've changed the script ever so slightly to make
                  wrapping more obvious.

                  @echo off
                  FOR /F "TOKENS=1" %%i IN (name.txt) DO (
                  sed "1,14 s/Reconnect.../Reconnect=90/" %%i\wyse\wnos\wnos.ini>c:\a.txt
                  move c:\a.txt %%i\wyse\wnos\wnos.ini
                  )

                  The error was the last line (deleted now) that was trying to remove the
                  temp file but it no longer existed, because I was using MOVE.





                  [Non-text portions of this message have been removed]
                • foxidrive
                  On Wed, 25 Jul 2007 12:30:25 -0500, Morris, Lamar ... It performs the replace only on lines 1 to 14. I may have counted incorrectly
                  Message 8 of 27 , Jul 25, 2007
                    On Wed, 25 Jul 2007 12:30:25 -0500, "Morris, Lamar" <LamarMorris@...>
                    wrote:

                    >Mic, can you explain what you're doing here.
                    >
                    >
                    >
                    >sed "1,14

                    It performs the replace only on lines 1 to 14. I may have counted
                    incorrectly when I removed some blank lines from the sample file.
                  • Morris, Lamar
                    Thanks. Lamar ________________________________ From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On Behalf Of foxidrive Sent: Wednesday,
                    Message 9 of 27 , Jul 25, 2007
                      Thanks.



                      Lamar



                      ________________________________

                      From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
                      Behalf Of foxidrive
                      Sent: Wednesday, July 25, 2007 12:33 PM
                      To: batchworld@yahoogroups.com
                      Subject: Re: [BATCH WORLD] SED Question



                      On Wed, 25 Jul 2007 12:30:25 -0500, "Morris, Lamar" <LamarMorris@...
                      <mailto:LamarMorris%40ti.com> >
                      wrote:

                      >Mic, can you explain what you're doing here.
                      >
                      >
                      >
                      >sed "1,14

                      It performs the replace only on lines 1 to 14. I may have counted
                      incorrectly when I removed some blank lines from the sample file.





                      [Non-text portions of this message have been removed]
                    • Morris, Lamar
                      That s probably the problem, the example I sent was an excerpt from a file and not the whole file. The could have from a few to many lines. I ll dink with it.
                      Message 10 of 27 , Jul 25, 2007
                        That's probably the problem, the example I sent was an excerpt from a
                        file and not the whole file. The could have from a few to many lines.
                        I'll dink with it.



                        Lamar







                        ________________________________

                        From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
                        Behalf Of foxidrive
                        Sent: Wednesday, July 25, 2007 12:33 PM
                        To: batchworld@yahoogroups.com
                        Subject: Re: [BATCH WORLD] SED Question



                        On Wed, 25 Jul 2007 12:30:25 -0500, "Morris, Lamar" <LamarMorris@...
                        <mailto:LamarMorris%40ti.com> >
                        wrote:

                        >Mic, can you explain what you're doing here.
                        >
                        >
                        >
                        >sed "1,14

                        It performs the replace only on lines 1 to 14. I may have counted
                        incorrectly when I removed some blank lines from the sample file.





                        [Non-text portions of this message have been removed]
                      • foxidrive
                        On Wed, 25 Jul 2007 12:38:34 -0500, Morris, Lamar ... Another day, another batch file. ;-) This has been tested (my apologies for
                        Message 11 of 27 , Jul 25, 2007
                          On Wed, 25 Jul 2007 12:38:34 -0500, "Morris, Lamar" <LamarMorris@...>
                          wrote:

                          >That's probably the problem, the example I sent was an excerpt from a
                          >file and not the whole file. The could have from a few to many lines.
                          >I'll dink with it.

                          Another day, another batch file. ;-)

                          This has been tested (my apologies for omitting that info to begin with in
                          this thread) but has had the specific paths added and variable changed to
                          %%a, which have not been tested.


                          @echo off
                          setlocal
                          FOR /F "TOKENS=1" %%a IN (name.txt) DO (
                          for /f "tokens=2 delims=[]" %%b in (
                          'find /n "Reconnect="^<%%a\wyse\wnos\wnos.ini^|find /n /v ""^|find "[1]"'
                          ) do (
                          sed "%%b s/Reconnect.../Reconnect=90/" %%a\wyse\wnos\wnos.ini>c:\a.txt
                          move c:\a.txt %%a\wyse\wnos\wnos.ini
                          )
                          )


                          It is 10 lines in total and should change only the first occurance of
                          "Reconnect=" in the ini file.

                          The triplet of find commands detect firstly all the "Reconnect=" lines, and
                          provides the line numbers using /n, then takes the first of those (by
                          renumbering those lines again) and uses the first line number in the sed
                          command to change only that line.
                        • Morris, Lamar
                          Many thanks Mic, you make all our lives easier with your scripting expertise, as usual the script works flawlessly. Lamar ________________________________
                          Message 12 of 27 , Jul 26, 2007
                            Many thanks Mic, you make all our lives easier with your scripting
                            expertise, as usual the script works flawlessly.



                            Lamar



                            ________________________________

                            From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
                            Behalf Of foxidrive
                            Sent: Thursday, July 26, 2007 1:52 AM
                            To: batchworld@yahoogroups.com
                            Subject: Re: [BATCH WORLD] SED Question



                            On Wed, 25 Jul 2007 12:38:34 -0500, "Morris, Lamar" <LamarMorris@...
                            <mailto:LamarMorris%40ti.com> >
                            wrote:

                            >That's probably the problem, the example I sent was an excerpt from a
                            >file and not the whole file. The could have from a few to many lines.
                            >I'll dink with it.

                            Another day, another batch file. ;-)

                            This has been tested (my apologies for omitting that info to begin with
                            in
                            this thread) but has had the specific paths added and variable changed
                            to
                            %%a, which have not been tested.

                            @echo off
                            setlocal
                            FOR /F "TOKENS=1" %%a IN (name.txt) DO (
                            for /f "tokens=2 delims=[]" %%b in (
                            'find /n "Reconnect="^<%%a\wyse\wnos\wnos.ini^|find /n /v ""^|find
                            "[1]"'
                            ) do (
                            sed "%%b s/Reconnect.../Reconnect=90/" %%a\wyse\wnos\wnos.ini>c:\a.txt
                            move c:\a.txt %%a\wyse\wnos\wnos.ini
                            )
                            )

                            It is 10 lines in total and should change only the first occurance of
                            "Reconnect=" in the ini file.

                            The triplet of find commands detect firstly all the "Reconnect=" lines,
                            and
                            provides the line numbers using /n, then takes the first of those (by
                            renumbering those lines again) and uses the first line number in the sed
                            command to change only that line.





                            [Non-text portions of this message have been removed]
                          • Garry Deane
                            ... a wyse wnos wnos.ini^|find /n /v ^|find [1] ... a wyse wnos wnos.ini c: a.txt ... Maybe I m missing something here but this seems overly complex. You
                            Message 13 of 27 , Jul 27, 2007
                              --- In batchworld@yahoogroups.com, foxidrive <foxidrive@...> wrote:
                              >
                              > Another day, another batch file. ;-)
                              >
                              > This has been tested (my apologies for omitting that info to
                              > begin with in this thread) but has had the specific paths added
                              > and variable changed to %%a, which have not been tested.
                              >
                              >
                              > @echo off
                              > setlocal
                              > FOR /F "TOKENS=1" %%a IN (name.txt) DO (
                              > for /f "tokens=2 delims=[]" %%b in (
                              > 'find /n "Reconnect="^<%%
                              a\wyse\wnos\wnos.ini^|find /n /v ""^|find "[1]"'
                              > ) do (
                              > sed "%%b s/Reconnect.../Reconnect=90/" %%
                              a\wyse\wnos\wnos.ini>c:\a.txt
                              > move c:\a.txt %%a\wyse\wnos\wnos.ini
                              > )
                              > )
                              >
                              >
                              > It is 10 lines in total and should change only the first
                              > occurance of "Reconnect=" in the ini file.
                              >
                              > The triplet of find commands detect firstly all the "Reconnect="
                              > lines, and provides the line numbers using /n, then takes the
                              > first of those (by renumbering those lines again) and uses the
                              > first line number in the sed command to change only that line.
                              >

                              Maybe I'm missing something here but this seems overly complex.
                              You can use the line range syntax in sed to only search and
                              replace up to the first occurrence of "Reconnect=" e.g.

                              sed "1,/Reconnect=/s/Reconnect=../Reconnect=90/" < in.txt > out.txt

                              Garry
                            • foxidrive
                              On Fri, 27 Jul 2007 08:50:20 -0000, Garry Deane ... We could have used you the other day Garry. :)
                              Message 14 of 27 , Jul 27, 2007
                                On Fri, 27 Jul 2007 08:50:20 -0000, "Garry Deane" <garrydeane@...>
                                wrote:

                                >> The triplet of find commands detect firstly all the "Reconnect="
                                >> lines, and provides the line numbers using /n, then takes the
                                >> first of those (by renumbering those lines again) and uses the
                                >> first line number in the sed command to change only that line.
                                >>
                                >
                                >Maybe I'm missing something here but this seems overly complex.
                                >You can use the line range syntax in sed to only search and
                                >replace up to the first occurrence of "Reconnect=" e.g.
                                >
                                >sed "1,/Reconnect=/s/Reconnect=../Reconnect=90/" < in.txt > out.txt
                                >
                                >Garry

                                We could have used you the other day Garry. :)
                              • Morris, Lamar
                                Thanks Garry, I ll test and add to my scripts folder. Lamar ________________________________ From: batchworld@yahoogroups.com
                                Message 15 of 27 , Jul 27, 2007
                                  Thanks Garry, I'll test and add to my scripts folder.



                                  Lamar



                                  ________________________________

                                  From: batchworld@yahoogroups.com [mailto:batchworld@yahoogroups.com] On
                                  Behalf Of Garry Deane
                                  Sent: Friday, July 27, 2007 3:50 AM
                                  To: batchworld@yahoogroups.com
                                  Subject: [BATCH WORLD] Re: SED Question



                                  --- In batchworld@yahoogroups.com <mailto:batchworld%40yahoogroups.com>
                                  , foxidrive <foxidrive@...> wrote:
                                  >
                                  > Another day, another batch file. ;-)
                                  >
                                  > This has been tested (my apologies for omitting that info to
                                  > begin with in this thread) but has had the specific paths added
                                  > and variable changed to %%a, which have not been tested.
                                  >
                                  >
                                  > @echo off
                                  > setlocal
                                  > FOR /F "TOKENS=1" %%a IN (name.txt) DO (
                                  > for /f "tokens=2 delims=[]" %%b in (
                                  > 'find /n "Reconnect="^<%%
                                  a\wyse\wnos\wnos.ini^|find /n /v ""^|find "[1]"'
                                  > ) do (
                                  > sed "%%b s/Reconnect.../Reconnect=90/" %%
                                  a\wyse\wnos\wnos.ini>c:\a.txt
                                  > move c:\a.txt %%a\wyse\wnos\wnos.ini
                                  > )
                                  > )
                                  >
                                  >
                                  > It is 10 lines in total and should change only the first
                                  > occurance of "Reconnect=" in the ini file.
                                  >
                                  > The triplet of find commands detect firstly all the "Reconnect="
                                  > lines, and provides the line numbers using /n, then takes the
                                  > first of those (by renumbering those lines again) and uses the
                                  > first line number in the sed command to change only that line.
                                  >

                                  Maybe I'm missing something here but this seems overly complex.
                                  You can use the line range syntax in sed to only search and
                                  replace up to the first occurrence of "Reconnect=" e.g.

                                  sed "1,/Reconnect=/s/Reconnect=../Reconnect=90/" < in.txt > out.txt

                                  Garry





                                  [Non-text portions of this message have been removed]
                                • henter2009
                                  I have the following question about sed and methacaracters: In the eg number 1, I escaped the +, to get any matches with 1 plus (1 or more characters) In the
                                  Message 16 of 27 , Oct 14, 2009
                                    I have the following question about sed and methacaracters:

                                    In the eg number 1, I escaped the +, to get any matches with 1 plus (1 or
                                    more characters)
                                    In the eg number 2, I escaped the *, to get any matches with 0 or more
                                    characters, but it scape the * and takes it at literal.

                                    Why it doesn't take + literal as well?
                                    How does it really works?
                                    Any help?




                                    1.) sed -ne '/t\+/Ip'

                                    tango
                                    tango > repeated
                                    balada > non repeated


                                    2.) sed -ne '/t\*/Ip'

                                    t8
                                    t*
                                    t*
                                    --
                                    View this message in context: http://www.nabble.com/SED-Question-tp25892283p25892283.html
                                    Sent from the Batch World mailing list archive at Nabble.com.
                                  Your message has been successfully submitted and would be delivered to recipients shortly.