Kindly check it: Camparison of files only column1 of 2 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Kindly check it: Camparison of files only column1 of 2 files
# 8  
Old 07-27-2012
awk

Hi,
You said col1 value on both the files are same thats why i provided the join suggestion.
Try this one,
Code:
awk 'FNR==NR{if($1 ~ /,/){split($1,b,",");for(i in b){a[i]=$2" "$3;}}else{a[$1]=$2" "$3;}next;}{if(a[$1]){print $0,a[$1];}}' file1  file2

Make sure that the col1 should have unique values.
Cheers,
Ranga:-)
# 9  
Old 07-27-2012
cheers!This has done gud wrk but not all the common entries are matched

for example
if the first file contain more than one time common entries it wont show the data present in front of all 1 digits.

so if the input files are like this

Code:
1,2,3                c          d 
1,4                     g          h 
1,2, 6,7                  k           c

and


Code:
1  x
2  u
3  s
4  l

output shuld contain all the data in same column with , mentioned between two words of same column with common entry

Code:
 1 x    c,g,k  d,h,c  
2  u    c,k      d,c
3  s    c       d 
4  l    g        h


Last edited by Scott; 07-27-2012 at 04:53 AM.. Reason: CODE tags not QUOTE tags
# 10  
Old 07-27-2012
awk

Hi,

Try this one,
Code:
awk 'FNR==NR{a[$1]=$2;next;}{if($1 ~ /,/){split($1,b,",");for(i in b){if(a[i]){print i,$2,$3,a[i];}}}else{if(a[$1]){print $0,a[$1];}}}' file2  file1

Again i assuming file2's col1 has unique values.
I hope it helps you.
Cheers,
Ranga:-)
This User Gave Thanks to rangarasan For This Post:
# 11  
Old 07-30-2012
Request to check

Hi all,

In one of the other files which I have to compare data is arrange dlike this Please let me knw the scripting


Code:
Mani Grover    1   2   3

Sumit Grover Saxena  1  3  4
  
Mani Grover    3   4  5

Harsh Grover     4  5  6

Mani Grover    4 5 6

Sumit saxena    5  6  8

the second file contain data



Code:
Mani Grover    z34  

Sushant Grover   z65  

Harsh Grover    z44

Rinku Saxena    x4y


I want the output shuld be



Code:
Mani Grover   z34     1,3,4   2,5,4   3 ,5,6

Harsh Grover     z44  4  5  6

# 12  
Old 07-30-2012
It would help if you could state the modus operandi of arriving at the output.
# 13  
Old 07-30-2012
Request to check

Hi

Thanks for reply.

Yes, first entries in first column( which can be combination of words like Mani Grover) of one file has to be matched with entries in first column of second file

If , there is common entries in both files
then, it should write the other entries the column 2,3,4 separated by comma in front of it in arrangement of columns.

And, it should also match data in column 2 in front of common entry wnd write before it.

Like if Mani Grover is common then output is mentioned in the above part of questions.

Mani

---------- Post updated at 05:58 AM ---------- Previous update was at 02:00 AM ----------

Hi all,

In one of the other files which I have to compare data is arrange dlike this Please let me knw the scripting


Code:
Mani Grover    1   2   3

Sumit Grover Saxena  1  3  4
  
Mani Grover    3   4  5

Harsh Grover     4  5  6

Mani Grover    4 5 6

Sumit saxena    5  6  8

the second file contain data



Code:
Mani Grover    z34  

Sushant Grover   z65  

Harsh Grover    z44

Rinku Saxena    x4y

I want the output shuld be



Code:
Mani Grover   z34     1,3,4   2,5,4   3 ,5,6

Harsh Grover     z44  4  5  6

[/QUOTE]
# 14  
Old 07-30-2012
Try this

Code:
awk 'NR==FNR{
		a[$1]=$0
	}

NR!=FNR{
	n=split($1,b,",");
	for(i=1;i<=n;i++)
		{	if(a[b[i]])	
				{
					print a[b[i]]" "$2" "$3
				}
		}
	}' file2 file1

And output is
Code:
1  x c d
2  u c d
3  s c d
4  l g h

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get CRC check sum of files in java EAR file without extracting .jar/.war files to disk.?

unzip -v gives CRC info of each file in a zip(in my case .EAR) file. # unzip -v my-application.ear Archive: my-application.ear Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 197981 Defl:N 183708 7%... (1 Reply)
Discussion started by: kchinnam
1 Replies

2. Shell Programming and Scripting

Check files and archive the files using sftp

Hi, I have to check the files in another server using sftp to do that, below is the code i am going with #!/bin/bash export SRC_FOLDER=$1 export ARC_FOLDER=$2 HOST=as07u3456 USER=relfag sftp ${USER}@${HOST} <<EOF cd $SRC_FOLDER/DSCOR ls bye EOF echo "done" whatever the files i... (8 Replies)
Discussion started by: ursrami
8 Replies

3. Shell Programming and Scripting

common entries of first column in 2 or 3 files:kindly check

Hi all, I have 3 files with such data first files second file third file I have to find common entries of first column in two ways 1) between 2 files (2 Replies)
Discussion started by: manigrover
2 Replies

4. Shell Programming and Scripting

Kindly check:remove duplicates with similar data in front of it

Hi all, I have 2 files containing data like this: so if there is same entry repeated in the column like1,2,3,4 I have to check if there is different entries column like 2,4 but similar entries for duplicatein column 2 like1,3 the output shuld be like this for first file ... (5 Replies)
Discussion started by: manigrover
5 Replies

5. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

6. Shell Programming and Scripting

need a shell script to extract the files from source file and check whether those files existonserve

Hi, I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is # echo $0 -sh My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies

7. Shell Programming and Scripting

How to change value in CSV columns and compare two files where Column1 is identical

Hi all, Could someone help me with the following issue: 1st I have an CSV file delimiter is ";" I I have a column 7 where I need to do some multiple mathem. operation, I need all values in this columns to be multiplied by 1.5 and create a new CSV file with the replaced values. 2nd. I... (3 Replies)
Discussion started by: kl1ngac1k
3 Replies

8. Shell Programming and Scripting

How to check files and move the results to differents files?

Hi, I am a newbie to shell scripting. here is my objective: 1)The shell program should take 2 parameters - ie-> DestinationFolder, WebFolder 2)Destination folder contains few files that has to has be verified and deleted. 3)WebFolder is a folder containing a list of master files 4)It... (1 Reply)
Discussion started by: sandhyagupta
1 Replies

9. Shell Programming and Scripting

check how many files in folder or total files in folder

Hi all, I have copied all my files to one folder.and i want to check how many files (count) in the folder recently moved or total files in my folder? please send me the query asap. (3 Replies)
Discussion started by: durgaprasad
3 Replies

10. Shell Programming and Scripting

comparing 2 files - kindly assist expert

Hi, I'm new in shell scripting and would like u guys to help on this. OS: Solaris 9 currently, i have 2 files. file1: hello hi test god file2: hi hello file1 is my masterfile, and i wanted to print out string that are in file1 and NOT in file2 and send out a mail (with the... (15 Replies)
Discussion started by: chew
15 Replies
Login or Register to Ask a Question