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

Re: [PBML] How can i take one column of one string?

Expand Messages
  • Marcos Onisto
    Hello, I ll try it! Thanks a lot, Marcos ... field that is ..%, but I d to take the only value without the % character. ... I know of two ways. 1) Use
    Message 1 of 6 , Dec 14, 2006
    • 0 Attachment
      Hello,

      I'll try it!

      Thanks a lot,

      Marcos


      Damien Carbery <daymobrew@...> wrote: --- In perl-beginner@yahoogroups.com, Marcos Onisto <mlonisto@...> wrote:
      >
      > Hello,
      >
      > One more question. I have the output below, I'm taking the five
      field that is ..%, but I'd to take the only value without the % character.
      >
      > /dev/dsk/c0t0d0s0 491831 347447 95201 79% /
      > /dev/dsk/c0t0d0s3 17144018 3403114 13569464 21% /usr
      > /dev/dsk/c0t0d0s6 1370511 96072 1219619 8% /export/home
      >
      > Is there one easy way to do it?
      >
      > I really appreciate some help.
      >
      > Thanks a lot,
      >
      > Marcos
      >

      I know of two ways.

      1) Use substitution to remove non-numeric chars.
      my $Field5 = '14%';
      $Field5 =~ s/\D*//g;
      print "Field5 = $Field5\n"; # Prints 14

      2) Validate the data and use grouping to extract the numbers.
      my $Field5 = '14%';
      if ( $Field5 =~ /^(\d+)/ )
      {
      print "Match = $1\n"; # Prints 14
      }
      else
      {
      print "Bad data - do something!\n";
      }

      The advantage of the second method is that it confirms that the data
      is valid (i.e. begins with a digit). It allows you to take action when
      the data is invalid.

      >
      > Marcos Onisto <mlonisto@...> wrote:
      Hello,
      >
      > That's it! It's work but I'm trying to understand how It act.
      >
      > Thanks a lot,
      >
      > Marcos
      >
      > Robert Brown <rdabman4@...> wrote:
      One possible answer
      >
      > my ($strg,$pct)="";
      > my @flds=();
      > $strg="/dev/dsk/cotodos6 1370511 96072 1219619 8% /export/home";
      > @flds=split(" ",$strg);
      > $pct=$flds[4]; # arrays start from zero
      > print "Fifth column field is $pct\n";
      >
      > ----- Original Message ----
      > From: Marcos Onisto <mlonisto@...>
      > To: perl-beginner@yahoogroups.com
      > Sent: Monday, December 11, 2006 1:29:31 PM
      > Subject: [PBML] How can i take one column of one string?
      >
      > Hello All,
      >
      > I have one string that follow below. How can i take the 8% or
      exactly 5 column?
      >
      > /dev/dsk/c0t0d0s6 1370511 96072 1219619 8% /export/home
      >
      > I really appreciate some help.
      >
      > Thanks a lot,
      >
      > Marcos






      ---------------------------------
      Any questions? Get answers on any topic at Yahoo! Answers. Try it now.

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.