Results 1 to 4 of 4

Thread: awk in perl

  1. #1
    Join Date
    Jan 2005
    Posts
    8

    Unanswered: awk in perl

    can someone tell me how do i use awk in perl?
    Or how do i get a particular field in a line having fields separated by ',' in a text file using perl ?

    Thanks,
    Kailash

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    An example for using awk in a perl-script:
    Code:
    #! /usr/bin/perl
    
    use strict;
    use warnings;
    
    my @array = `awk '{print \$2}' awk.text`;
    print $_,"\n" for(@array);
    The awk.text:
    this is a
    test whether the
    script is working
    or not !
    board.perl-community.de - The German Perl-Community

  3. #3
    Join Date
    Jan 2005
    Posts
    8

    awk for single line of text

    how do i use awk for single line of text instead of a file..
    eg:
    $line = this, is, my, line;

    Can I use something like this:
    $line2 = `awk 'BEGIN { FS = "," } {print \$2}' $line1`;

    But this doesnt work!!

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Take a look at the a2p executable that is supplied with many versions of Perl. It takes an awk script, and produces an equivelent Perl script as output.

    What you really want in this case is the split() function, something like:
    Code:
    @list = split /,/; print $list[1];
    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •