Results 1 to 3 of 3

Thread: using awk

  1. #1
    Join Date
    Feb 2004
    Posts
    143

    Unanswered: using awk

    I have a flat file file1.txt with fixed length fields. It is like this :

    100<>JOHN <>ERERXC<>4343<>YMC
    200<>MARK <>BNDF <>3434<>BNU
    300<>SCOTT <>TRTRR <>4343<>JNI
    400<>BENJAMIN <>VZDSS <>3434<>IJM

    I want to remove the whole of the 3rd column above. In other words. my output needs
    to be as below in another file called file2.txt

    100<>JOHN <>4343<>YMC
    200<>MARK <>3434<>BNU
    300<>SCOTT <>4343<>JNI
    400<>BENJAMIN <>3434<>IJM

    How do I do this using awk ? Or is there another method ? Thanks

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool


    Use substr:
    Code:
    awk 'print substr($0,1,30) substr($0,41);}' file1.txt >file1.new

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Jan 2006
    Posts
    32
    Code:
    awk 'BEGIN { FS = "<>"; OFS = "<>" }; {print $1, $2, $4}' file1.txt


    .

Posting Permissions

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