awk to print record not equal specific pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to print record not equal specific pattern
# 15  
Old 05-08-2013
Quote:
tell me whether [awk command] is correct or not?
Here is the input you most recently posted:
Code:
$ cat input
2    9647701612350         9647701168456         262       23        1303031257462B0300 1303031259182B0300 92        9647701146402  0
5    9647706046060         9647801139306         263       32        1303031255312B0300 1303031259182B0300 227       9647701146402  0
6    9647706046060         9647801139306         263       32        130325255312B0300 1303251259182B0300 227       9647701146402  0
8    9647701612350         9647701168456         22       262        1303111257462B0300 1303111259182B0300 92        9647701146402  0
9    9647701612350         9647701168456         262      700        1303131257462B0300 1303131259182B0300 92        9647701146402  0
10   9647701612350         9647701168456         22       263        1303031257462B0300 1303031259182B0300 92        9647701146402  0
12   9647706046060         9647801139306         263       32        130303255312B0300 1303032259182B0300 227       9647701146402  0

Here is what the code you just posted produces (I removed stray ! character):
Code:
$ awk '($4 ~/263/  && $6 <=130304) {print }'  input
5    9647706046060         9647801139306         263       32        1303031255312B0300 1303031259182B0300 227       9647701146402  0
12   9647706046060         9647801139306         263       32        130303255312B0300 1303032259182B0300 227       9647701146402  0

Does it make those two lines when you run it? If those two lines are the ones you want, in a sense it's correct. On the other hand, the output differs from what you posted as expected output in your last previous post, which had five output lines. In that sense, it seems not correct.

When you said "filter out" before, the five expected output lines suggested you meant "exclude", "not print". Maybe the definition has changed, and you want to "print" if $4 == 263 and $6 <= 130304. Perhaps the problem is getting better defined. It would not hurt to post another input file, and the expected output, if you would like.

Since $6 is such a big field, I think it makes more sense to compare with the substr of $6 that just has the first six numbers, and not depend on some odd way it might compare 130304 with the much longer field.
This User Gave Thanks to hanson44 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find key pattern and print selected lines for each record

Hi, I need help on a complicated file that I am working on. I wanted to extract important info from a very huge file. It is space delimited file. I have hundred thousands of records in this file. An example content of the inputfile as below:- ## ID Ser402 Old; 23... (2 Replies)
Discussion started by: redse171
2 Replies

2. Shell Programming and Scripting

Help with print out record if first and next line follow specific pattern

Input file: pattern1 100 250 US pattern2 50 3050 UK pattern3 100 250 US pattern1 70 1050 UK pattern1 170 450 Mal pattern2 40 750 UK . . Desired Output file: pattern1 100 250 US pattern2 50 3050 UK pattern1 170 450 Mal pattern2... (3 Replies)
Discussion started by: cpp_beginner
3 Replies

3. Shell Programming and Scripting

Problem to print out record got smallest number in specific column

Hi, Anybody know how to print out the record that shown smallest number among column 3 and column 4 Case 1 Input : 37170 37196 77 51 37174 37195 73 52 37174 37194 73 53 Case 1 Output : 37170 37196 77 51 Case 2 Input : 469613 469660 73 ... (4 Replies)
Discussion started by: cpp_beginner
4 Replies

4. Shell Programming and Scripting

Execution problem with print out record that follow specific pattern

Hi, Do anybody know how to print out only those record that column 1 is "a" , then followed by "b"? Input file : a comp92 2404242 2405172 b comp92 2405303 2406323 b comp92 2408786 2410278 a comp92 2410271 2410337 a comp87 1239833 1240418 b comp87... (3 Replies)
Discussion started by: patrick87
3 Replies

5. Shell Programming and Scripting

Help with print out line that have different record in specific column

Input file 1: - 7367 8198 - 8225 9383 + 9570 10353 Input file 2: - 2917 3667 - 3851 4250 + 4517 6302 + 6302 6740 + 6768 7524 + 7648 8170 + 8272 8896 + 8908 9915 - 10010 ... (18 Replies)
Discussion started by: perl_beginner
18 Replies

6. UNIX for Dummies Questions & Answers

How to Detect Specific Pattern and Print the Specific String after It?

I'm still beginner and maybe someone can help me. I have this input: the great warrior a, b, c and what i want to know is, with awk, how can i detect the string with 'warrior' string on it and print the a, b, and c seperately, become like this : Warrior Type a b c Im still very... (3 Replies)
Discussion started by: radynaraya
3 Replies

7. Shell Programming and Scripting

Help with print out all relevant record if match particular pattern

Input file: data100_content1 420 700 data101_content1 107 516 data101_content2 194 773 data101_content3 195 917 data104_content2 36 325 data105_content1 505 605 data106_content1 291 565 ... (7 Replies)
Discussion started by: perl_beginner
7 Replies

8. Shell Programming and Scripting

Using awk, print all the lines where field 8 is equal to x

Using awk, print all the lines where field 8 is equal to x I really did try, but this awk thing is really hard to figure out. file1.txt"Georgia","Atlanta","2011-11-02","x","","","","" "California","Los Angeles","2011-11-03","x","","","",""... (2 Replies)
Discussion started by: charles33
2 Replies

9. Shell Programming and Scripting

Regarding multiline record searching with specific pattern

Dear Experts, I need to extract specific records from one file which has multiline records. Input file pattern is: ============ aaaaaaaa bbbbbbbb asdf 1234 cccccccc dddddddd ============ aaaaaaaa bbbbbbbb qwer 2345 cccccccc dddddddd (7 Replies)
Discussion started by: dhiraj4mann
7 Replies

10. Shell Programming and Scripting

Grep for a pattern and print entire record

Hi friends, This is my very first post on forum, so kindly excuse if my doubts are found too silly. I am trying to automate a piece of routine work and this is where I am stuck at the moment-I need to grep a particular ID through a file containing many records(which start with <LRECORD> and end... (6 Replies)
Discussion started by: faiz1985
6 Replies
Login or Register to Ask a Question