Sponsored Content
Top Forums Shell Programming and Scripting [solved] Diff between two files by grep Post 302441704 by feelmyfrd on Monday 2nd of August 2010 05:58:44 AM
Old 08-02-2010
[solved] Diff between two files by grep

My requiremeny is as follows,

I have two files

file a
Code:
A BONES RD,NHILL,3418,VIC 
37TH PARALLEL RD,DEEP LEAD,3385,VIC 
4 AK RD,OAKEY,4401,QLD 
A & J FARRS RD,BARMOYA,4703,QLD 
A B PATTERSON DR,ARUNDEL,4214,QLD 
A BLAIRS RD,BUCKRABANYULE,3525,VIC

file b
Code:
A BONES RD,NHILL,3418,VIC 
37TH PARALLEL RD,DEEP LEAD,3385,VIC 
4 AK RD,OAKEY,4401,QLD 
A & J FARRS RD,BARMOYA,4703,QLD 
A B PATTERSON DR,ARUNDEL,4214,QLD

On greping content of each row of file 1 in file 2, if no result found re-direct to file3
In this case file 3 should have below content

file 3
Code:
A BLAIRS RD,BUCKRABANYULE,3525,VIC

My code is as follows,
Code:
cat  file1| while read line
do
grep   -v  "$line'"  file2  > file3    
done

Output I' getting,
Code:
A BONES RD,NHILL,3418,VIC
37TH PARALLEL RD,DEEP LEAD,3385,VIC
4 AK RD,OAKEY,4401,QLD
A & J FARRS RD,BARMOYA,4703,QLD
A B PATTERSON DR,ARUNDEL,4214,QLD

Please help me,I tried grep -f file1 file2 > file3 but its getting following error
Code:
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

please give u r suggestion with out using -f option

Moderator's Comments:
Mod Comment Use code tags please, ty.
feelmyfrd
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies

2. Shell Programming and Scripting

Find duplicates from multuple files with 2 diff types of files

I need to compare 2 diff type of files and find out the duplicate after comparing each types of files: Type 1 file name is like: file1.abc (the extension abc could any 3 characters but I can narrow it down or hardcode for 10/15 combinations). The other file is file1.bcd01abc (the extension... (2 Replies)
Discussion started by: ricky007
2 Replies

3. Shell Programming and Scripting

Solved: finding diff in files

i want to compare 2 files and generate below 3 files: 1. new lines 2. updated lines 3. deleted lines are there any one liners for each one of them. Note the method to find duplicates is based on field 1, values are separated by '|' example: test1 (older file) 1|XXX 2|YYY... (3 Replies)
Discussion started by: manishma71
3 Replies

4. Shell Programming and Scripting

[solved] merging two files and writing to another file- solved

i have two files as file1: 1 2 3 file2: a b c and the output should be: file3: 1~a 2~b 3~c (1 Reply)
Discussion started by: mlpathir
1 Replies

5. Shell Programming and Scripting

Diff between grep .* file name and grep '.*' filename

Hi, Can anyone let me know what is difference between grep .* foo.c grep '.*' foo.c I am not able to understand what is exact difference. Thanks in advance (2 Replies)
Discussion started by: SasDutta
2 Replies

6. Shell Programming and Scripting

[Solved] Help with grep script

Hi, I'm having trouble with a script to copy one line out of multiple files in a directory and copy to a file called test. I've tried the code below but it copies one line out of the first file multiple times not one line out of all the files. Would someone help? I'm very new to all this. ... (8 Replies)
Discussion started by: bob101
8 Replies

7. Shell Programming and Scripting

[Solved] Issue with grep

Hi everyone I am trying to write a script to check if file systems are mounted, and also validate the permission; then do a whole bunch of other things. I am facing a problem with grep. For example, if the mountpoints are: /dev/XYZ_lv /abc/XYZ jfs2 Nov 25 20:36... (4 Replies)
Discussion started by: nimo
4 Replies

8. UNIX for Dummies Questions & Answers

[Solved] Grep multiple files and display first match

I have a need to grep a large number of files, but only display the first result from each file. I have tried to use grep, but am not limited to it. I can use perl and awk as well. Please help! (9 Replies)
Discussion started by: dbiggied
9 Replies

9. Shell Programming and Scripting

Grep -v -f and sort|diff which way is faster

Hi Gurus, I have two big files. I need to compare the different. currently, I am using sort file1 > file1_temp; sort file2 > file2_tmp diff file1_tmp file2_tmp I can use command grep -v -f file1 file2 just wondering which way is fast to compare two big files. Thanks... (4 Replies)
Discussion started by: ken6503
4 Replies

10. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 07:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy