using cat and grep to display missing records


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers using cat and grep to display missing records
# 1  
Old 01-13-2007
using cat and grep to display missing records

Gentle Unix users,

Can someone tell me how I can use a combination of the cat and grep command to display records that are in FileA but missing in FileB.

cat FileA one line at a time and grep to see if it is in fileB. If it is ignore.
If line is not in fileB display the line.

Thanks in advance.
# 2  
Old 01-13-2007
Try...
Code:
$ head file[12]
==> file1 <==
aaa
ccc
eee
ggg
hhh
kkk

==> file2 <==
aaa
ddd
ggg
kkk

$ grep -v -f file2 file1
ccc
eee
hhh

# 3  
Old 01-13-2007
you can use diff command for this.why you want to use cat,grep and all

diff <file1> <file2>
crypto $ cat >2.txt
krish
aish
crypto $ cat >3.txt
krish
aish
fish
crypto $ diff 2.txt 3.txt
2a3
> fish
crypto $
# 4  
Old 01-13-2007
Thanks guys.

I used the grep -v -f file1 file2 but ended up an out of memory error as the files were too large.

Ended up using the diff option though I had to edit the output file to remove
the line indication such as 2a3 in the example and the < > file indicator for each line.

Once again thanks
# 5  
Old 01-13-2007
checkout this command for getting only the diff output without > 2a3

diff 2.txt 3.txt|awk 'NR==2 {print$2}'

or

diff 2.txt 3.txt|sed "1 d"|awk '{print$2}'

which ever suits your requirement
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding missing records and Dups

I have a fixed width file. The records looks something similar to below: Type ID SSN NAME .....AND SOME MORE FIELDS A1 1234 ..... A1 1234 ..... B1 1234 ..... M2 4567 ..... M2 4567 ..... N2 4567 ..... N2 4567 ..... A1 9999 N2 9999 Now if A1 is present then B1 has to be present.... (2 Replies)
Discussion started by: Saanvi1
2 Replies

2. Shell Programming and Scripting

Script with ^M causes display issue with cat or more

I have a script to do a couple simple but repetitive commands on files that are provided to us. One of the things is to get rid of the line feeds. This is the section that is causing problems, i even cut this section into its own file to make sure nothing else was affecting it. #!/usr/bin/bash... (4 Replies)
Discussion started by: oly_r
4 Replies

3. Shell Programming and Scripting

extract data and display the missing value

Hi, I have thousands of data in 1 file that need to be sorted out. My file is like below:- File1.txt condition 1 scaf_27 CDS 48317 48517 "e_gww2.27.12.1" Id 35277 scaf_27 stop_cod 48317 48319 "e_gww2.27.12.1" scaf_27 CDS 48518 49107 "e_gww2.27.12.1" ... (4 Replies)
Discussion started by: redse171
4 Replies

4. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

5. Shell Programming and Scripting

cat redirect EOF missing text

Hello attempting to redirect out to create a startup script in solaris. The steps are working but the $1 entry is being left out. syntax below and content of output file below. cat > S99build << EOF > #!/bin/bash > case $1 in > 'start') > /usr/os-buildsol.sh > > ;; > esac > exit 0 >... (3 Replies)
Discussion started by: juanb25
3 Replies

6. Shell Programming and Scripting

Display variables in CAT area

Hi All, I've got a script to output YAML data, and I want to display data that's held inside variables inside one large CAT area. What's the easiest way to do this? cat << "END" --- classes: - general_image - $intro #Variable 1 - $mid #Variable 2 ... (2 Replies)
Discussion started by: glarizza
2 Replies

7. UNIX for Advanced & Expert Users

Urgent: How can i get the missing records from one file out of two

Hi, I have two files say A and B, Both files have some common records few records which are unique to file A and unique to file B. Can anyone please help me out to find the records which are present in only B Please consider the files are of too large size. Thanks:confused: (1 Reply)
Discussion started by: Shiv@jad
1 Replies

8. UNIX for Dummies Questions & Answers

How to Display a range of values in the output of cat

When I use this command I get an output of some numbers cat ac.20070511 | cut -d" " -f19 Is there any way for me to display only the numbers that are greater than 1000 but not all the numbers in the ouput. Can any one help me with this. :) (8 Replies)
Discussion started by: venu_nbk
8 Replies

9. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies

10. UNIX for Dummies Questions & Answers

deleting records with a missing field

I had to delete rows when a record was missing a field. My solution was cut -c 202-402 ${dataFile} | awk '{if (substr($0,103,30) !~ /^ *$/) print $0} >> ${workFile} The cut is because they came two records to a row. Anyone want to offer a more elegant solution? (2 Replies)
Discussion started by: gillbates
2 Replies
Login or Register to Ask a Question