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

Cutting columns fm a txt file w/PERL

Expand Messages
  • ericvia@airmail.net
    Please bear with a beginner - I am FORCING myself to learn PERL, so although I know I can do what I want to do using AWK, I want to be able to do such things
    Message 1 of 1 , Jun 1, 2001
    • 0 Attachment
      Please bear with a beginner -

      I am FORCING myself to learn PERL, so although I know I can do what
      I want to do using AWK, I want to be able to do such things in PERL
      scripts - but cannot easily understand it as well.

      If I have a text file like so, called - "story.txt", that reads like:

      48 dogs barking at house
      27 mules living in trees
      19 elephants eating the grass

      And I want to split each into it's own separate txt file, so I end
      up with:

      one txt file with the first word called perhaps "howmany.txt"
      48
      27
      19

      and the second, perhaps "animal.txt"
      dogs
      mules
      elephants

      and so on - you get the picture I think - I could do easily what come
      to mind easily in AWK:

      awk '{print $1} story.txt > howmany.txt
      awk '{print $2} story.txt > animal.txt
      and so on down the line.

      I am going to GUESS with my limited knowledge of PERL and say that
      I would instead read in "story.txt" as an array? Yes? And I could
      name each part of the array? - and once that's done it's a matter of
      doing anything I want with each part of the array correct? So -
      (thinking out loud here) - I can "open" the story.txt,
      and...and....and then....why I'll.......I'll.......Okay - this is
      where my ideas run out I'm afraid - I'm just hoping that perhaps PERL
      can do this as easily as AWK can?

      But then, - dare I saw that if PERL (or awk for that matter) can be
      able to split up the words like I want to write them to text files,
      why can't he just work with right where they're at!?? (But then
      perhaps that would be too much for me right now and I can do that
      later)

      Thanks in advance for any help - y'all are the greatest people in
      the world.

      Eric in TX
    Your message has been successfully submitted and would be delivered to recipients shortly.