Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-08-2012
Registered User
 
Join Date: Jul 2005
Posts: 94
Thanks: 11
Thanked 0 Times in 0 Posts
Awk search help

Hi,

Want to know what does it returns.


Code:
$ awk '$1 == /Jan/' inv

$ awk '$1 = /Jan/' inv --- What does this one signify.
1 13 25 15 115
1 21 36 64 620

$ awk '$1 ~ /Jan/' inv
Jan  13  25  15 115
Jan  21  36  64 620

Thanks in advance.
Sponsored Links
    #2  
Old 06-08-2012
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Location: Switzerland - GE
Posts: 4,633
Thanks: 118
Thanked 256 Times in 245 Posts
Dont know... You did not show us what was is the file inv for a start...
You also di not mention your OS (awk differ depending of OS you know...)
Sponsored Links
    #3  
Old 06-08-2012
Registered User
 
Join Date: Jul 2005
Posts: 94
Thanks: 11
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by vbe View Post
Dont know... You did not show us what was is the file inv for a start...
You also di not mention your OS (awk differ depending of OS you know...)
I am using CYGWIN_NT-5.1


Code:
$ cat inv

Jan  13  25  15 115
Feb  15  32  24 226
Mar  15  24  34 228
Apr  31  52  63 420
May  16  34  29 208
Jun  31  42  75 492
Jul  24  34  67 436
Aug  15  34  47 316
Sep  13  55  37 277
Oct  29  54  68 525
Nov  20  87  82 577
Dec  17  35  61 401

Jan  21  36  64 620
Feb  26  58  80 652
Mar  24  75  70 495
Apr  21  70  74 514

    #4  
Old 06-08-2012
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,334
Thanks: 143
Thanked 1,754 Times in 1,591 Posts
In the second awk, you are assigning the outcome of /Jan/ (1 if true, 0 if false) to field 1.., in the first one, you are comparing 0 or 1 to the value of field 1..
What you are probably looking for is:

Code:
awk '$1=="Jan"' inv

or

Code:
awk '$1==m' m=Jan inv

The Following User Says Thank You to Scrutinizer For This Useful Post:
vanand420 (06-08-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Binary Search Tree Search problem meredith1990 Programming 1 02-27-2012 10:23 AM
sed help - search/copy from one file and search/paste to another ncwxpanther Shell Programming and Scripting 5 08-21-2011 10:56 AM
Search files with specfic extention and later search content lovi_v UNIX for Advanced & Expert Users 2 07-14-2008 12:05 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 09:24 AM
Advanced Search Problems.. Search by User Name Neo Post Here to Contact Site Administrators and Moderators 1 05-19-2003 12:28 AM



All times are GMT -4. The time now is 04:59 AM.