1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

select rows based on column contents

Discussion in 'Linux and Unix' started by grinder182533, Dec 20, 2010.

Thread Status:
Not open for further replies.
  1. grinder182533

    grinder182533 Thread Starter

    Joined:
    Jun 1, 2009
    Messages:
    72
    Hi
    My pipe delimited .txt file contains rows with 10 columns.
    Can anyone advise how I output to file only those rows with the letters ‘ci’
    as the first 2 characters in the 3rd column ?
    Many thanks
     
  2. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Hi grinder182533,

    I would cat the .txt file into a pipe, and then use (nawk, gawk, or awk) to filter only the 3rd column with the first two letters 'ci'.

    Example:
    $ cat file.txt | nawk '{ if substr($3,1,2) = "ci"; print $0 }'

    -- Tom
     
  3. angel115

    angel115

    Joined:
    Feb 6, 2010
    Messages:
    8
    Code:
    nawk '{ if substr($3,1,2) = "ci"; print $0 }' -f file.txt
    Would be a bit faster.

    Avoiding using 'cat' is always better.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - select rows based
  1. tintex
    Replies:
    4
    Views:
    666
  2. Sarabjit
    Replies:
    5
    Views:
    804
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/969571

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice