Grep in column 2

  • Follow


Is there any way to use grep in column 2 in a file ? 
I want get all lines in a file whose column 2 haves actual date.

cat file

    eagle   04/31/2001
    bee     09/15/2002
    dog     12/03/2004   --> I want output  
    cats    12/03/2004   --> these 2 lines !

Thanks.
0
Reply contracer11 12/3/2004 9:23:31 PM

In article <ddf392ea.0412031323.2afa1777@posting.google.com>,
 contracer11@uol.com.br (Shiva MahaDeva) wrote:

> Is there any way to use grep in column 2 in a file ? 
> I want get all lines in a file whose column 2 haves actual date.
> 
> cat file
> 
>     eagle   04/31/2001
>     bee     09/15/2002
>     dog     12/03/2004   --> I want output  
>     cats    12/03/2004   --> these 2 lines !
> 
> Thanks.

Use awk or nawk.  It's made for this sort of thing.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...



0
Reply Michael 12/3/2004 10:34:09 PM



Shiva MahaDeva wrote:
> Is there any way to use grep in column 2 in a file ? 
> I want get all lines in a file whose column 2 haves actual date.
> 
> cat file
> 
>     eagle   04/31/2001
>     bee     09/15/2002
>     dog     12/03/2004   --> I want output  
>     cats    12/03/2004   --> these 2 lines !
> 
> Thanks.

Use awk:

awk '$2 ~ /12\/03\/2004/ {print $0)' file
0
Reply Triffid 12/3/2004 10:48:40 PM

On 3 Dec 2004 13:23:31 -0800, contracer11@uol.com.br (Shiva MahaDeva)
wrote:

>Is there any way to use grep in column 2 in a file ? 
>I want get all lines in a file whose column 2 haves actual date.
>
>cat file
>
>    eagle   04/31/2001
>    bee     09/15/2002
>    dog     12/03/2004   --> I want output  
>    cats    12/03/2004   --> these 2 lines !
>

Grep doesn't care about the column. Use AWK if you do. But in this
case, 

grep "12/03/2004" file  

Would work just fine.


-- 
gburnore@databasix dot com          
---------------------------------------------------------------------------
                  How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore                       |  �۳�ݳ޳�ݳ��ۺݳ޳�ݳݳ޳�ݳ��۳
                                      |  �۳�ݳ޳�ݳ��ۺݳ޳�ݳݳ޳�ݳ��۳
DataBasix                             |  �۳�ݳ޳�ݳ��ۺݳ޳�ݳݳ޳�ݳ��۳
                                      |  �۳ 3 4 1 4 2  ݳ޳ 6 9 0 6 9 �۳
Black Helicopter Repair Svcs Division |     Official Proof of Purchase
===========================================================================
      Want one?  GET one!   http://signup.databasix.com
===========================================================================
0
Reply Gary 12/3/2004 11:19:22 PM

$ cat > /tmp/aaa <<EOF
eagle         04/31/2001
12/03/2004    09/15/2002
dog           12/03/2004
cats          12/03/2004
EOF

$ grep '[^ ].* *12/03/2004' /tmp/aaa
dog           12/03/2004
cats          12/03/2004
$

Vitaly Filatov
http://members.tripod.com/Vitaly_Filatov

Shiva MahaDeva ???????:
> Is there any way to use grep in column 2 in a file ? 
> I want get all lines in a file whose column 2 haves actual date.
> 
> cat file
> 
>     eagle   04/31/2001
>     bee     09/15/2002
>     dog     12/03/2004   --> I want output  
>     cats    12/03/2004   --> these 2 lines !
> 
> Thanks.

0
Reply Vitaly 5/10/2005 11:46:21 PM

4 Replies
601 Views

(page loaded in 0.097 seconds)

Similiar Articles:













7/20/2012 5:57:56 PM


Reply: