The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
combining fields in two text fields shocker Shell Programming and Scripting 3 01-16-2008 11:27 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Search for a pattern from the result of search boopathi_d Shell Programming and Scripting 3 12-05-2007 09:54 AM
search and replace different fields tungaw2004 UNIX for Dummies Questions & Answers 3 03-29-2007 04:16 AM
Advanced Search Problems.. Search by User Name Neo Post Here to Contact Site Administrators and Moderators 1 05-19-2003 01:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-23-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
Arrow How to search for two fields

Hi all,

I have a file with format as below:

cat 0 animal 90 number90 cat_number_name
cat 1 animal 91 number91 cat_animal_name
cat 2 animal 92 number92 cat_name_animal


kiwi 0 bird 90 number90 kiwi_number_name
kiwi 1 bird 91 number91 kiwi_animal_name
kiwi 2 bird 92 number92 kiwi_name_animal

I want to search for $1=cat and $2=0 and print using awk
For eg:
the O/p should be after the search (for the above )
cat 2 animal 92 number92 cat_name_animal

Another words, i want to print line where the first field is cat and second field is 0


Thanks in advance
JS
  #2 (permalink)  
Old 04-23-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Hi Jisha,

i think your supposed output for $1=cat and $2=o is

cat 0 animal 90 number90 cat_number_name

The follwing may solve the purpose for you

awk '{if ( $1=="cat" && $2==0 ) {print $0}}' file
  #3 (permalink)  
Old 04-23-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Actually the "if" is inherent in how awk works, so that can be simplified.


Code:
awk '$1 == "cat" && $2 == 0 { print }' file

  #4 (permalink)  
Old 04-23-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
Thank you so much !!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0