Awk search help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Awk search help
# 1  
Old 06-08-2012
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.
# 2  
Old 06-08-2012
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...)
# 3  
Old 06-08-2012
Quote:
Originally Posted by vbe
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
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

This User Gave Thanks to Scrutinizer For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

awk variable search and line count between variable-search pattern

Input: |Running the Rsync|Sun Oct 16 22:48:01 BST 2016 |End of the Rsync|Sun Oct 16 22:49:54 BST 2016 |Running the Rsync|Sun Oct 16 22:54:01 BST 2016 |End of the Rsync|Sun Oct 16 22:55:45 BST 2016 |Running the Rsync|Sun Oct 16 23:00:02 BST 2016 |End of the Rsync|Sun Oct 16 23:01:44 BST 2016... (4 Replies)
Discussion started by: busyboy
4 Replies

3. Shell Programming and Scripting

How to search for right word using awk?

Hi- I have issue with the code to get the input file reformat --Goal is reformat and print out only column name one per line, leading space or trailing space will be removed... --TABLE1.DDL as input file, and content of file as show below REPLACE VIEW TABLE1 ( ID ,COL1 ... (3 Replies)
Discussion started by: lv99
3 Replies

4. Shell Programming and Scripting

Awk: search and replace

I have a file which requires modification via a shell script. Need to do the following: 0. take input from user for new text. 1. search for a keyword in the file. 2. going forward, search for another keyword. 3. Replace this line with user supplied input. for e.g., my file has the following... (6 Replies)
Discussion started by: chingupt
6 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Shell Programming and Scripting

How to do a simple awk search?

Hello I am trying to do global search on access log files for a date and for either 'Error|error' string ls -lrt *access* | grep "Sep 23" | awk '{print $9}'|xargs awk '/23\/Sep\/2011/ && /Error/ || /error' Above matches All lines with 'error' as well unfortunately. Is there a... (6 Replies)
Discussion started by: delphys
6 Replies

7. Shell Programming and Scripting

awk search if else

Hi, I want to search for a particular string using awk and print "Found" or "Not Found" depending on the search. On searching this forum i got this code but it is not working: (6 Replies)
Discussion started by: rishav
6 Replies

8. Shell Programming and Scripting

awk search

i guys, i have a bash script , and it works, but i need an awk file, and i can't convert this code like: #!/bin/awk -f ..... my script #!/bin/bash awk '/\<FIRST\>|\<SECOND\>|\<THIRD\>|\<ZERO\>/' DOC.txt thanks :) (4 Replies)
Discussion started by: felito
4 Replies

9. Shell Programming and Scripting

awk search pattern

Hi, I have a log file which contains lines like below: 2010-07-19 07:13:19,021 ERROR system ...(text) 2010-07-19 07:22:03,427 ERROR system ...(text) class com... (text) 2010-07-19 07:23:19,026 ERROR system ...(text) class com... (text) each line is a separate line... I am given the a... (14 Replies)
Discussion started by: a27wang
14 Replies

10. Shell Programming and Scripting

AWK - no search results

Hi all, I'm new to awk and I'm experiencing syntax error that I don't know how to resolve. Hopefully some experts in this forum can help me out. I created an awk file that look like this: $ cat myawk.awk BEGIN { VAR1=PATTERN1 VAR2=PATTERN2 } /VAR1/ { flag=1 } /VAR2/ { flag=0 } {... (7 Replies)
Discussion started by: hk18
7 Replies
Login or Register to Ask a Question