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

Not a perl question..

Expand Messages
  • Sreeram B S
    Hi , This is not a perl question.. but since it needed this info quickly .. I am posting it here. Please don t mind. I have a query. I would like to change all
    Message 1 of 3 , Nov 3, 2003
      Hi ,
      This is not a perl question.. but since it needed this info quickly .. I am posting it here. Please don't mind.

      I have a query. I would like to change all occurences of a word,say data1, to another word, say info1 in a file, say file1. I would like to do it using command-line.
      I tried using the command sed. I tried it in Solaris..like this:
      /usr/xpg4/bin/sed -n 's/data1/info1/g' file1
      I could see the changed data on the screen.. but the changes were not done in the file. THen I tried this:
      /usr/xpg4/bin/sed -n 's/data1/info/w file2' file1
      Now file2 contained only those lines which contained info1(i.e which contained data1 in original file) but not the other contents of original file.
      I would like to know the command-line for changing the contents of the file and retain the non-changed parts of the file.

      Thanks in advance,
      Sreeram



      ---------------------------------
      Do you Yahoo!?
      Exclusive Video Premiere - Britney Spears

      [Non-text portions of this message have been removed]
    • Damien Carbery
      ... quickly .. I am posting it here. Please don t mind. ... data1, to another word, say info1 in a file, say file1. I would like to do it using command-line.
      Message 2 of 3 , Nov 3, 2003
        --- In perl-beginner@yahoogroups.com, Sreeram B S <sreeramabsc@y...>
        wrote:
        > Hi ,
        > This is not a perl question.. but since it needed this info
        quickly .. I am posting it here. Please don't mind.
        >
        > I have a query. I would like to change all occurences of a word,say
        data1, to another word, say info1 in a file, say file1. I would like
        to do it using command-line.
        > I tried using the command sed. I tried it in Solaris..like this:
        > /usr/xpg4/bin/sed -n 's/data1/info1/g' file1
        > I could see the changed data on the screen.. but the changes were
        not done in the file. THen I tried this:
        > /usr/xpg4/bin/sed -n 's/data1/info/w file2' file1
        > Now file2 contained only those lines which contained info1(i.e
        which contained data1 in original file) but not the other contents of
        original file.
        > I would like to know the command-line for changing the contents
        of the file and retain the non-changed parts of the file.
        >
        > Thanks in advance,
        > Sreeram
        >

        Jeff's solution will of course work.
        The problem with what you were doing it you were not redirecting the
        changes to a new file. You only needed to append '> file2' to your
        command:

        /usr/xpg4/bin/sed -n 's/data1/info1/g' file1 > file2

        Aside: Any reason for not using /usr/bin/sed?
      • merlyn@stonehenge.com
        ... Sreeram This is not a perl question.. but since it needed this info Sreeram quickly .. I am posting it here. Please don t mind. Do you mind if I
        Message 3 of 3 , Nov 3, 2003
          >>>>> "Sreeram" == Sreeram B S <sreeramabsc@...> writes:

          Sreeram> This is not a perl question.. but since it needed this info
          Sreeram> quickly .. I am posting it here. Please don't mind.

          Do you mind if I advertise a car for sale here too? I need it sold
          quickly, and there's a lot of people here who would really like to buy
          my car given the opportunity. It's even Perl related, because a lot
          of Perl programmers drive the type of car I drive!

          Yes, I mind.

          Consider yourself chastised in public.

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
          See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
        Your message has been successfully submitted and would be delivered to recipients shortly.