Grep the non-matching lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep the non-matching lines
# 1  
Old 12-21-2012
Grep the non-matching lines

Hi,

I need to make a script to extract the number that are not in a file.

Example:
I have file-A that has 100000 (70000-799999) numbers. And a file-B with number that already are in the system. Now I need to know/get the numbers that are not in system.

I was thinking something like this:

cat file-A | grep -v "file-b" >> file-C but it is not posible to grep -v from a text file. Maybe a loop file ? Smilie

Advise please. tnxSmilie

Code:
file-A:
700000
700001
700002
700003
700004
700005
700006
700007
..
..
799997
799998
799999

Code:
File-B:
700002
700005
700010
799997

Code:
file-C:

 Invert the sense of matching, to select non-matching lines

# 2  
Old 12-21-2012
Code:
grep -vf file-B file-A > file-C

# 3  
Old 12-21-2012
It did not worked.

Code:
 
grep -vf list.txt range.txt > output.txt


Last edited by Scott; 12-21-2012 at 09:08 AM.. Reason: Code tags
# 4  
Old 12-21-2012
have a look at the command
Code:
comm

# 5  
Old 12-21-2012
Doesn't work? It certainly should.

Code:
$ cat file1
11
12
13
14
15
16
17
18
19
20
 
$ cat file2
12
14
16
18
 
$ grep -vf file2 file1
11
13
15
17
19
20

# 6  
Old 12-21-2012
Tnx. it worked very easy with COMM command.

Code:
 
comm -3 file-A file-B >file-C
 
comm -3 range.txt list.txt >output.txt


Last edited by Scott; 12-21-2012 at 09:27 AM.. Reason: Use code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Matching and where, using grep

May somebody can give me a hint. I want to find using the command "grep" a certain word or term in a foo.txt file. By using the following command grep -i word file1 > newfile4 it puts it into a new foo.txt-file, the n times it matches. Fine, it matches n times, but how could I specify where... (2 Replies)
Discussion started by: 1in10
2 Replies

2. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

3. Shell Programming and Scripting

How to print few lines before and after matching word is found suing grep?

Hi, here are few lines present in the logs. I want to grep on Error and print few lines before and after Error word is found line1 Line2 Line3 Error Line4 Line5 Line6 Line7 I want the output to be Line2 Line3 Error Line5 (1 Reply)
Discussion started by: arghadeep adity
1 Replies

4. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

5. UNIX for Dummies Questions & Answers

Grep to find lines matching given patern in a file

When I try with patern matching in a file with below code works cat scj_drive_commands | egrep '/app/oracle/build_lib/pkg32|/app/oracle/build_lib/pkg33' But when I have code with patern searching using of below does not work ! cat scj_drive_commands | egrep... (3 Replies)
Discussion started by: Siva SQL
3 Replies

6. Shell Programming and Scripting

Insert lines above matching line with content from matching

Hi, I have text file: Name: xyz Gender: M Address: "120_B_C; ksilskdj; lsudlfw" Zip: 20392 Name: KLM Gender: F Address: "65_D_F; wnmlsi;lsuod;,...." Zip:90233I want to insert 2 new lines before the 'Address: ' line deriving value from this Address line value The Address value in quotes... (1 Reply)
Discussion started by: ysrini
1 Replies

7. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

8. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

9. Shell Programming and Scripting

AIX equivalent to GNU grep's -B and -A [print lines after or before matching lines]

Hi folks I am not allowed to install GNU grep on AIX. Here my code excerpt: grep_fatal () { /usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP" } Howto the same on AIX based machine? from manual GNU grep ‘--after-context=num’ Print num lines of trailing context after... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

10. Shell Programming and Scripting

pattern matching lines using the date, and then joining the lines

Hi Guys, Was trying to attempt the below using awk and sed, have no luck so far, so any help would be appreciated. Current Text File: The first line has got an "\n", and the second line has got spaces/tabs then the word and "\n" TIME SERVER/CLIENT TEXT... (6 Replies)
Discussion started by: eo29
6 Replies
Login or Register to Ask a Question