Sponsored Content
Top Forums Shell Programming and Scripting compare 2 files and extract the data which is not present in other file with condition Post 302596383 by rajniman on Tuesday 7th of February 2012 09:23:04 AM
Old 02-07-2012
thanks kalpeer for replying

i have one more file as
FileD
Code:
funny       mou1
funny       mou2
raspe       mou4
damn       mou1

this file is a csv with /t.
i want to find all values with the first column of this file in fileB and then check for in that line if the second column vvalues are present or not .

for eg suppose in fileB there is a line
Code:
funnymou1:20112
funnymou2:34470
raspmou3:nhdhv
raspmou4:38748

fileD is 1st content is of 1st column is "funny"
so funny would be checked in fileB if found then "funny" second column will be checked i.e mou1 will be checked in that line if present than ok. if not present than it will be written in other fileE.if first column of fileD is present than only second column of fileD is checked in that line .if first column field can be present in more than one rows in fileB all lines of fileB should be then compared with second column of fileD if found then not written ... if not found then written in fileE
so for
raspe mou4 : as raspe is not present in fileB it will be written in fileE as output

so
funny mou1
is present so it will not be written in fileE
next
funny mou2 is also present in fileB so not writen
now
raspe mou4
damn mou1 will be wriiten in fileE as it is not present in fileB.

o/p of fileE
Code:
funny   mou1
funny   mou2

can it be done using awk ... i have records more than 80000

---------- Post updated at 09:22 AM ---------- Previous update was at 08:52 AM ----------

hi kalpeer,

the code
grep -f fileB fileA | awk ' $1 >= 3' > fileC
is not working Smilie
as fileA contents may be present in a line of fileB(means in between of that line in fileB and not as a whole) but not vice versa..
means total line of fileB cannot be present in fileA
if fileB contains
2011890done1
3235235funny

as fileA
03 done
04 funny

so the code isnt working ..
please help!

Last edited by rajniman; 02-07-2012 at 10:25 AM.. Reason: some chages
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare data in 2 files and delete if file exist

Hi there, I have written a script called "compare" (see below) to make comparison between 2 files namely test_put.log and Output_A0.log #!/bin/ksh while read file do found="no" while read line do echo $line | grep $file > /dev/null if then echo $file found found="yes" break fi... (3 Replies)
Discussion started by: lweegp
3 Replies

2. UNIX for Dummies Questions & Answers

how do i compare and extract similiar data

I have 2 files. The first file contains user names in one column. The second, and considerably longer, file contains user names in the first column and corresponding full names in the second column. Currently these are in the .xls format. I'd like to be able to compare file1 with file2 and extract... (2 Replies)
Discussion started by: raptrmastr
2 Replies

3. Shell Programming and Scripting

How to compare 2 files & get only few columns based on a condition related to both files?

Hiiiii friends I have 2 files which contains huge data & few lines of it are as shown below File1: b.dat(which has 21 columns) SSR 1976 8 12 13 10 44.00 39.0700 70.7800 7.0 0 0.00 0 2.78 0.00 0.00 0 0.00 2.78 0 NULL ISC 1976 8 12 22 32 37.39 36.2942 70.7338... (6 Replies)
Discussion started by: reva
6 Replies

4. Shell Programming and Scripting

Compare columns of 2 files based on condition defined in a different file

I have a control file which tells me which are the fields in the files I need to compare and based on the values I need to print the exact value if key =Y and output is Y , or if output is Y/N then I need to print only Y if it matches or N if it does not match and if output =N , then skip the feild... (7 Replies)
Discussion started by: newtoawk
7 Replies

5. Shell Programming and Scripting

How to compare data from 2 zip files and capture the new records from file2 to a new file

I have 2 zip files which have about 20 million records in each file. file 2 will have additional records than file 1. I want to compare the records in both the files and capture the new records from file 2 into another file file3. Please help me with a command/script which provides me the desired... (8 Replies)
Discussion started by: koneru
8 Replies

6. Shell Programming and Scripting

compare 2 files and return unique lines in each file (based on condition)

hi my problem is little complicated one. i have 2 files which appear like this file 1 abbsss:aa:22:34:as akl abc 1234 mkilll:as:ss:23:qs asc abc 0987 mlopii:cd:wq:24:as asd abc 7866 file2 lkoaa:as:24:32:sa alk abc 3245 lkmo:as:34:43:qs qsa abc 0987 kloia:ds:45:56:sa acq abc 7805 i... (5 Replies)
Discussion started by: anurupa777
5 Replies

7. Shell Programming and Scripting

Compare two numbers which present in two different files

Hi, I need to compare the two floating or integer numbers which present in two different files, Ex: File 1: col1 col2 col3 11 ssa 13.60 12 ssb 11.00 13 ssc 754.00 File 2:col1 col2 col3 11 sa 12.75 12 sb 11.00 13 sc 763.00 here i have to compare 3 column if 1st column match,... (8 Replies)
Discussion started by: Shenbaga.d
8 Replies

8. Shell Programming and Scripting

Compare two files and write data to second file using awk

Hi Guys, I wanted to compare a delimited file and positional file, for a particular key files and if it matches then append the positional file with some data. Example: Delimited File -------------- Byer;Amy;NONE1;A5218257;E5218257 Byer;Amy;NONE1;A5218260;E5218260 Positional File... (3 Replies)
Discussion started by: Ajay Venkatesan
3 Replies

9. UNIX for Beginners Questions & Answers

Compare between two files with condition

Hello there. I am trying to compare two files. File1 Austria Mobile 1 United Kingdom Mobile 1 ... File2 Austria Mobile Vien 2 Austria Mobile Ostr 0 United Kingdom Mobile Dev 0.7 United Kingdom Mobile OST 1.5 What i want to do is to compare both files and... (12 Replies)
Discussion started by: dragonfly85
12 Replies

10. Shell Programming and Scripting

Compare 2 files and extract the data which is present in other file - awk is not working

file2 content f1file2 content f1,1,2,3,4,5 f1,2,4,6,8,10 f10,1,2,3,4,5 f10,2,4,6,8,10 f5,1,2,3,4,5 f5,2,4,6,8,10awk 'FNR==NR{a;next}; !($1 in a)' file2 file1output f10,1,2,3,4,5 f10,2,4,6,8,10 f5,1,2,3,4,5 f5,2,4,6,8,10awk 'FNR==NR{a;next}; ($1 in a)' file2 file1output nothing... (4 Replies)
Discussion started by: gksenthilkumar
4 Replies
FORTUNE(6)							 BSD Games Manual							FORTUNE(6)

NAME
fortune -- print a random, hopefully interesting, adage SYNOPSIS
fortune [-aefilosw] [-m pattern] [[N%] file/dir/all] DESCRIPTION
When fortune is run with no arguments it prints out a random epigram. Epigrams are divided into several categories, where each category is subdivided into those which are potentially offensive and those which are not. The options are as follows: -a Choose from all lists of maxims, both offensive and not. (See the -o option for more information on offensive fortunes.) -e Consider all fortune files to be of equal size (see discussion below on multiple files). -f Print out the list of files which would be searched, but don't print a fortune. -i Ignore case for -m patterns. -l Long dictums only. -m pattern Print out all fortunes which match the regular expression pattern. See regex(3) for a description of patterns. -o Choose only from potentially offensive aphorisms. Please, please, please request a potentially offensive fortune if and only if you believe, deep down in your heart, that you are willing to be offended. (And that if you are, you'll just quit using -o rather than give us grief about it, okay?) ... let us keep in mind the basic governing philosophy of The Brotherhood, as handsomely summarized in these words: we believe in healthy, hearty laughter -- at the expense of the whole human race, if needs be. Needs be. --H. Allen Smith, "Rude Jokes" -s Short apothegms only. -w Wait before termination for an amount of time calculated from the number of characters in the message. This is useful if it is exe- cuted as part of the logout procedure to guarantee that the message can be read before the screen is cleared. The user may specify alternative sayings. You can specify a specific file, a directory which contains one or more files, or the special word all, which says to use all the standard databases. Any of these may be preceded by a percentage, which is a number N between 0 and 100 inclusive, followed by a '%' character. If it is, there will be an N percent probability that an adage will be picked from that file or directory. If the percentages do not sum to 100, and there are specifications without percentages, the remaining percent will apply to those files and/or directories, in which case the probability of selecting from one of them will be based on their relative sizes. As an example, given two databases funny and not-funny, with funny twice as big, saying $ fortune funny not-funny will get you fortunes out of funny two-thirds of the time. The command $ fortune 90% funny 10% not-funny will pick out 90% of its fortunes from funny (the ``10%'' is unnecessary, since 10% is all that's left). The -e option says to consider all files equal; thus $ fortune -e is equivalent to $ fortune 50% funny 50% not-funny Datafiles for fortune are created by the strfile(8) utility, which is not installed by default, The source code for this utility can be found in /usr/src/games/fortune/strfile, if it exists. FILES
/usr/share/games/fortune/* Fortune files. SEE ALSO
regex(3), random(6), rot13(6) BSD
September 9, 2004 BSD
All times are GMT -4. The time now is 06:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy