Sponsored Content
Top Forums Shell Programming and Scripting awk to print out lines that do not fall between range in file Post 302998446 by Don Cragun on Thursday 1st of June 2017 06:26:00 PM
Old 06-01-2017
Quote:
Originally Posted by cmccabe
The above is what I am trying to do as each element is treated as a pair, so it. That is each $2 is combined with a $3. Basically, the opposite of my code. I can seem to print the lines in the range, but not the lines not in the range. Thank you Smilie.
You have confused the matter more. You are not looking at $3 in file2 so it can't possibly affect the output produced by your script. If you just want to reverse the output produced by your script change it to:
Code:
awk '
    NR==FNR{for(i=$2;i<=$3;++i) d[$1,i] = $6; next}
    !d[$1,$2]{print $0}' file1 file2

or, using the default action when a condition is met:
Code:
awk '
    NR==FNR{for(i=$2;i<=$3;++i) d[$1,i] = $6; next}
    !d[$1,$2]' file1 file2

or to take less space:
Code:
awk '
    NR==FNR{for(i=$2;i<=$3;++i) d[$1,i]; next}
    !(($1,$2) in d)' file1 file2

This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

retrieve lines from file which fall under the given date range

Hi, I need to retrieve the lines which fall under the given date range. eg:In a log file,i have the lines which will have the timestamp. the input will be some date range.eg: from date:03/Jan/2008,to date:24/Jul/2008.so now i want to retrieve the lines which have the timestamp between these... (5 Replies)
Discussion started by: Sharmila_P
5 Replies

2. Shell Programming and Scripting

Print lines matching value(s) in other file using awk

Hi, I have two comma separated files. I would like to see field 1 value of File1 exact match in field 2 of File2. If the value matches, then it should print matched lines from File2. I have achieved the results using cut, paste and egrep -f but I would like to use awk as it is efficient way and... (7 Replies)
Discussion started by: SBC
7 Replies

3. Shell Programming and Scripting

How to print first matching range in awk?

following is input - <Schema> <schema_name>admin</schema_name> <Version>1.1</Version> <schema_name>admin</schema_name> <Version>1.2</Version> </Schema> ... (12 Replies)
Discussion started by: thearpit
12 Replies

4. Shell Programming and Scripting

awk print lines in a file

Dear All, a.txt A 1 Z A 1 ZZ B 2 Y B 2 AA how can i use awk one line to achieve the result: A Z|ZZ B Y|AA Thanks (5 Replies)
Discussion started by: jimmy_y
5 Replies

5. Shell Programming and Scripting

awk to print range of fields

Hi file.in and file.out are in csv format. the code I have now is, cat file.in | awk -F"," '!($1$2$3$4$5$6$7$8 in a){a;print $0}' > file.out Here, I am printing entire line using $0. however, I want to print $1 to $150 and it should be in csv format. Cut -d is not good in performace.... (3 Replies)
Discussion started by: krishnix
3 Replies

6. Shell Programming and Scripting

print range of lines matching pattern and previous line

Hi all, on Solaris 10, I'd like to print a range of lines starting at pattern but also including the very first line before pattern. the following doesn't print the range starting at pattern and going down to the end of file: cat <my file> | sed -n -e '/<pattern>{x;p;}/' I need to include the... (1 Reply)
Discussion started by: siriche
1 Replies

7. Shell Programming and Scripting

Sed print range of lines between line number and pattern

Hi, I have a file as below This is the line one This is the line two <\XMLTAG> This is the line three This is the line four <\XMLTAG> Output of the SED command need to be as below. This is the line one This is the line two <\XMLTAG> Please do the need to needful to... (4 Replies)
Discussion started by: RMN
4 Replies

8. Shell Programming and Scripting

Grep range of lines to print a line number on match

Hi Guru's, I am trying to grep a range of line numbers (based on match) and then look for another match which starts with a special character '$' and print the line number. I have the below code but it is actually printing the line number counting starting from the first line of the range i am... (15 Replies)
Discussion started by: Kevin Tivoli
15 Replies

9. UNIX for Beginners Questions & Answers

Advise on how to print range of lines above and below a number?

Hi, I have attached an output file which is some kind of database file mapping. It is basically like an allocation mapping of a tablespace and its datafile/s. The output is generated by the SQL script that I found from 401 Authorization Required Excerpts of the file are as below: ... (2 Replies)
Discussion started by: newbie_01
2 Replies

10. UNIX for Beginners Questions & Answers

TCL script to print range of lines between patterns

Hi I am having a code as stated below module abcd( a , b , c ,da , fa, na , ta , ma , ra , ta, la , pa ); input a , b, da ,fa , na , ta , ma; output c , ra ,ta , la ,pa ; wire a , b , da , fa ,na , ta , ma; endmodule I need to match the string... (1 Reply)
Discussion started by: kshitij
1 Replies
diff3(1)						      General Commands Manual							  diff3(1)

NAME
diff3 - Compares three files SYNOPSIS
diff3 [-e | -x | -E | -X | -3] file1 file2 file3 The diff3 command reads three versions of a file and writes to standard output the ranges of text that differ. OPTIONS
Creates an edit script for use with the ed command to incorporate into file1 all changes between file2 and file3 (that is, the changes that normally would be flagged ==== and ====3). Produces an edit script to incorporate only changes flagged ====. These are similar to -e and -x, respectively, but treat overlapping changes (that is, changes that are flagged ==== in the normal listing) differently. The overlap- ping lines from both files are inserted by the edit script, bracketed by <<<<<< and >>>>>> lines. The -E option is used by RCS merge to ensure that overlapping changes in the merged files are preserved and brought to someone's attention. Produces an edit script to incorpo- rate only changes flagged ====3. DESCRIPTION
The diff3 command reads three versions of a file and writes to standard output the ranges of text that differ, flagged with the following codes: All three files differ. file1 differs. file2 differs. file3 differs. The type of change needed to convert a given range of a given file to match another file is indicated in one of these two ways in the out- put: Text is to be added after line number number1 in file, where file is 1, 2, or 3. Text in the range line number1 to line number2 is to be changed. If number1 = number2, the range may be abbreviated to number1. The original contents of the range follow immediately after a c indication. When the contents of two files are identical, diff3 does not show the contents of the lower-numbered file, although it shows the location of the identical lines for each. NOTES
Editing scripts produced by the -e option cannot create lines consisting only of a single . (dot). EXAMPLES
To list the differences among three files, enter: diff3 fruit.a fruit.b fruit.c fruit.a, fruit.b, and fruit.c contain the following data: fruit.a: banana grape kiwi lemon mango orange peach pare fruit.b: apple banana grapefruit kiwi orange peach pear fruit.c: grape grapefruit kiwi lemon mango orange peach pear The output from diff3 shows the differences between these files as follows. (The comments on the right do not appear in the output.) ==== All three files are different. 1:1,2c - Lines 1 and 2 of the first file, fruit.a banana grape 2:1,3c - Lines 1 through 3 of fruit.b apple banana grapefruit 3:1,2c - Lines 1 and 2 of fruit.c grape grapefruit ====2 The second file, fruit.b, is different. 1:4,5c - Lines 4 and 5 are the same in fruit.a and fruit.c. 2:4a 3:4,5c - To make fruit.b look the same, add text after line 4. lemon mango ====1 The first file, fruit.a, is different. 1:8c pare 2:7c - Line 7 of fruit.b and line 8 of fruit.c are the same. 3:8c pear FILES
Helper program. SEE ALSO
Commands: bdiff(1), cmp(1), comm(1), diff(1), ed(1) diff3(1)
All times are GMT -4. The time now is 08:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy