AWK - Unix

This is a discussion on AWK - Unix ; hi, I am having following txt file. ------------------------------------------------------------------- 00032 Clemson Univ, Howard , Dept Chem, Clemson, SC 29634 USA. 00032 Clemson Univ, Howard , Films, Clemson, SC 29634 USA. 10032 Oak Ridge Natl Lab, High , Oak Ridge, TN 37831 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: AWK

  1. AWK

    hi,

    I am having following txt file.
    -------------------------------------------------------------------
    00032 Clemson Univ, Howard , Dept Chem, Clemson, SC 29634 USA.
    00032 Clemson Univ, Howard , Films, Clemson, SC 29634 USA.
    10032 Oak Ridge Natl Lab, High , Oak Ridge, TN 37831 USA.
    12029 Oak Ridge Natl Lab, Oak Ridge, TN 37831 USA.
    00029 Univ Texas, Dept Phys, Austin, TX 78712 USA.

    ------------------------------------------------------------------

    i want output in following manner.


    00032 Clemson Univ
    00032 Clemson Univ
    10032 Oak Ridge Nat1 Lab
    12029 Oak Ridge Nat1 Lab
    00029 Univ Texas


    i.e first filed (number), and second filed upto first comma.


  2. Re: AWK

    In <1130344167.350437.11520@g43g2000cwa.googlegroups.c om> "friend.05@gmail.com" writes:

    > I am having following txt file.
    > -------------------------------------------------------------------
    > 00032 Clemson Univ, Howard , Dept Chem, Clemson, SC 29634 USA.
    > 00032 Clemson Univ, Howard , Films, Clemson, SC 29634 USA.
    > 10032 Oak Ridge Natl Lab, High , Oak Ridge, TN 37831 USA.
    > 12029 Oak Ridge Natl Lab, Oak Ridge, TN 37831 USA.
    > 00029 Univ Texas, Dept Phys, Austin, TX 78712 USA.
    > ------------------------------------------------------------------


    > i want output in following manner.


    > 00032 Clemson Univ
    > 00032 Clemson Univ
    > 10032 Oak Ridge Nat1 Lab
    > 12029 Oak Ridge Nat1 Lab
    > 00029 Univ Texas


    > i.e first filed (number), and second filed upto first comma.


    Easy -- just tell awk that you want the fields to be separated by
    commas instead of spaces by using the -F argument:

    awk -F, '{print $1}' textfile

    This example does preserve the spacing between the number and the start
    of the university name, so if you want to eliminate the extra spaces, pass
    the output though sed, like so:

    awk -F, '{print $1}' textfile | sed 's/ */ /'

    --
    John Gordon "It's certainly uncontaminated by cheese."
    gordon@panix.com


  3. Re: AWK



    friend.05@gmail.com wrote:

    > hi,
    >
    > I am having following txt file.
    > -------------------------------------------------------------------
    > 00032 Clemson Univ, Howard , Dept Chem, Clemson, SC 29634 USA.
    > 00032 Clemson Univ, Howard , Films, Clemson, SC 29634 USA.
    > 10032 Oak Ridge Natl Lab, High , Oak Ridge, TN 37831 USA.
    > 12029 Oak Ridge Natl Lab, Oak Ridge, TN 37831 USA.
    > 00029 Univ Texas, Dept Phys, Austin, TX 78712 USA.
    >
    > ------------------------------------------------------------------
    >
    > i want output in following manner.
    >
    >
    > 00032 Clemson Univ
    > 00032 Clemson Univ
    > 10032 Oak Ridge Nat1 Lab
    > 12029 Oak Ridge Nat1 Lab
    > 00029 Univ Texas
    >
    >
    > i.e first filed (number), and second filed upto first comma.
    >


    awk -F, '{$1=$1;print $1}' file


+ Reply to Thread