select rows based on column contents

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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
 
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
 
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Members online

Top