Sponsored Content
Top Forums Shell Programming and Scripting Compare 2 files and find missing fields awk Post 302953773 by phaethon on Tuesday 1st of September 2015 10:29:54 AM
Old 09-01-2015
Compare 2 files and find missing fields awk

Hello experts!
I have 2 files.

file1 is a list file containing uniquely names. e.g.:
Code:
name1 number number
name2 number number
name5 number number
name10 number number
...


file2
is a data file arbitrary containing the names of file1 in paragraphs separated by "10" e.g.
Code:
name4   random_number
name5 random_nuber
10
name4   random_number
name6   random_number
name10 random_number
10
...

what I want is to get the names of file2 that is missing from file1 e.g
Code:
name4
name6

I have tried with
Code:
 awk ' FNR==NR{a[$1]++;next}!a[$1] { print $1}'  file1 file2

but I get all the 10s of file2 and repeatingly the sequence of stations
e.g.
Code:
10
10
10
name6
10
name6
10
...

Thank you in advance!

Last edited by vbe; 09-01-2015 at 11:36 AM.. Reason: code tags please, not ICODE
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

2. UNIX for Dummies Questions & Answers

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

3. Shell Programming and Scripting

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (3 Replies)
Discussion started by: yerruhari
3 Replies

4. Shell Programming and Scripting

Compare files in two folders and delete missing ones

I do not know much about shell scripting so I am at a loss here. If someone can help me, that would be great! I have two directories /dir1 /dir2 I need to delete all files from /dir1 and that does not have a correspondent file in /dir2. It should NOT check file suffixes in /dir2 . Why?... (20 Replies)
Discussion started by: kaah
20 Replies

5. Shell Programming and Scripting

Compare 2 folders to find several missing files among huge amounts of files.

Hi, all: I've got two folders, say, "folder1" and "folder2". Under each, there are thousands of files. It's quite obvious that there are some files missing in each. I just would like to find them. I believe this can be done by "diff" command. However, if I change the above question a... (1 Reply)
Discussion started by: jiapei100
1 Replies

6. Shell Programming and Scripting

Compare fields in 2 files using AWK

Hi unix gurus, I have a urgent requirement, I need to write a AWK script to compare each fields in 2 files using AWK. Basically my output should be like this. file1 row|num1|num2|num3 1|one|two|three 2|one|two|three file2 row|num1|num2|num3 1|one|two|three 2|one|two|four ... (5 Replies)
Discussion started by: rashmisb
5 Replies

7. Shell Programming and Scripting

AWK Compare files, different fields, output

Hi All, Looking for a quick AWK script to output some differences between two files. FILE1 device1 1.1.1.1 PINGS device1 2.2.2.2 PINGS FILE2 2862 SITE1 device1-prod 1.1.1.1 icmp - 0 ... (4 Replies)
Discussion started by: stacky69
4 Replies

8. Shell Programming and Scripting

Compare two files and get only missing names

I need to compare two files (oldfile1 & newfile). Need to ignore the values which are present in both files. At the same time, i need to get only records in new file. Tried using Join -v1 -v2 oldfile1 newfile (suspect it has not worked as expected). could anyone of you please help me here. (5 Replies)
Discussion started by: Selva_2507
5 Replies

9. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

10. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies
__gnu_parallel::random_number(3cxx)									       __gnu_parallel::random_number(3cxx)

NAME
__gnu_parallel::random_number - SYNOPSIS
Public Member Functions unsigned long genrand_bits (int bits) uint32 operator() () uint32 operator() (uint64 local_supremum) random_number () random_number (uint32 seed, uint64 supremum=0x100000000ULL) Detailed Description Random number generator, based on the Mersenne twister. Definition at line 41 of file random_number.h. Constructor &; Destructor Documentation __gnu_parallel::random_number::random_number () [inline] Default constructor. Seed with 0. Definition at line 73 of file random_number.h. __gnu_parallel::random_number::random_number (uint32seed, uint64supremum = 0x100000000ULL) [inline] Constructor. Parameters: seed Random seed. supremum Generate integer random numbers in the interval [0,supremum). Definition at line 84 of file random_number.h. Member Function Documentation unsigned long __gnu_parallel::random_number::genrand_bits (intbits) [inline] Generate a number of random bits, run-time parameter. Parameters: bits Number of bits to generate. Definition at line 108 of file random_number.h. uint32 __gnu_parallel::random_number::operator() () [inline] Generate unsigned random 32-bit integer. Definition at line 93 of file random_number.h. uint32 __gnu_parallel::random_number::operator() (uint64local_supremum) [inline] Generate unsigned random 32-bit integer in the interval [0,local_supremum). Definition at line 99 of file random_number.h. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Thu Aug 2 2012 __gnu_parallel::random_number(3cxx)
All times are GMT -4. The time now is 07:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy