Compare 2 files yet again but with a twist


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare 2 files yet again but with a twist
# 8  
Old 11-21-2008
Still doesn't work like this - I get no output?

[root@lab02 tmp]# /usr/xpg4/bin/awk 'NR==FNR{_[$1]=$2;next}$2=$2 FS _[$1]' gdl dkl
[root@lab02 tmp]#

files look like this:

gdl:
15. 392
19. 79
25. 14
28. 3
29. 2
3. 14
32. 11
41. 4
42. 8
43. 4
44. 1
45. 3
46. 1
47. 1
49. 4
50. 2
52. 2
53. 7

dkl:
0. c1t0d0
1. c2t0d0
2. c2t1d0
3. c2t2d0
4. c2t3d0
5. c2t4d0
6. c2t5d0
7. c2t8d0
8. c2t9d0
9. c2t10d0
10. c2t11d0
11. c2t12d0
12. c2t13d0
13. c3t0d0
14. c3t1d0
15. c3t2d0
16. c3t3d0
17. c3t5d0
18. c3t8d0
19. c3t9d0
20. c3t10d0
21. c3t11d0
22. c3t13d0
23. c6t0d0
24. c6t1d0
25. c6t2d0
26. c6t3d0
27. c6t4d0
28. c6t5d0
29. c6t6d0
30. c6t7d0
31. c6t8d0
32. c6t9d0
33. c6t10d0
34. c6t18d0
35. c6t19d0
36. c6t20d0
37. c6t21d0
38. c6t22d0
39. c6t23d0
40. c6t24d0
41. c6t25d0
42. c6t26d0
43. c7t0d0
44. c7t1d0
45. c7t2d0
46. c7t3d0
47. c7t4d0
48. c7t5d0
49. c7t6d0
50. c7t7d0
51. c7t8d0
52. c7t9d0
53. c7t10d0
55. c7t19d0
57. c7t21d0
58. c7t22d0
59. c7t23d0
60. c7t24d0
61. c7t25d0
62. c7t26d0
63. c11t0d0
64. c11t1d0
65. c11t2d0
66. c11t3d0
67. c11t4d0
68. c13t0d0
69. c13t1d0
70. c13t2d0
71. c13t3d0
72. c13t4d0
73. c13t5d0
74. c13t9d0
75. c13t10d0
76. c13t11d0
77. c13t12d0
78. c13t13d0

Last edited by Autumn Tree; 11-21-2008 at 10:20 AM..
# 9  
Old 11-21-2008
Quote:
Originally Posted by Autumn Tree
Still doesn't work like this - I get no output?

[root@lab02 tmp]# /usr/xpg4/bin/awk 'NR==FNR{_[$1]=$2;next}$2=$2 FS _[$1]' gdl dkl
[root@lab02 tmp]#
Swap the input file positions Smilie

Code:
dkl gdl

# 10  
Old 11-21-2008
d'oh - should've tried that first... thanks m8!!!
# 11  
Old 11-23-2008
Quote:
Originally Posted by yogi_raj_143
It seems you are dumping & combining the rows which have common first element in the row for each files
you can use join command



refer man join for more details
In order to use join the input files should be sorted.
On Solaris, for example, using bash (because of the process substitution),
you can use something like this:

Code:
join -o 2.1 2.2 1.2 <(sort dkl) <(sort gdl)

# 12  
Old 11-24-2008
Code:
nawk 'NR==FNR {_[$1]=$0}
NR!=FNR {
if(_[$1]!="")
	print _[$1]" "$2
}' f1 f2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Listing, with a Twist?

Greetings! I have a quick question which must be deferred to those with greater skill than myself :) In this situation, I wish to create a list of all the files on an entire partition in descending order sorted by date. I tried numerous switches for ls, and found this line to be the closest... (4 Replies)
Discussion started by: LinQ
4 Replies

2. Shell Programming and Scripting

Simple two file compare with twist

I have file1 and file2 I lookup field3 from file2 in field1 of file1 and if there is a match, output field 2,3,5 from file2. I now want to add field2 of file1 in the output. I suspect what I have to do is read the entire line of file1 into a 2 dim array? pls help. (1 Reply)
Discussion started by: tmonk1
1 Replies

3. Shell Programming and Scripting

Simple two file compare with twist

I have file1 and file2 I lookup field3 from file2 in field1 of file1 and if there is a match, output field 2,3,5 from file2. I now want to add field2 of file1 in the output. I suspect what I have to do is read the entire line of file1 into a 2 dim array? pls help. here is my code: ... (9 Replies)
Discussion started by: jack.bauer
9 Replies

4. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

5. Shell Programming and Scripting

Incrementing with a twist - please help

I'm currently trying to write a ksh or csh script that would change the name of a file found in directories and attach to the name an incrementing three digit number. I know how to write a script that will go: 000, 001, 002, 003, etc The twist is I need more increments then allowed by a 3... (11 Replies)
Discussion started by: Rust
11 Replies

6. Shell Programming and Scripting

How to merge two files with a slight twist

Hi, a brief introduction on the soundex python module(english sound comparison): import soundex.py a = "neu yorkk" b = "new york city" print soundex.sound_similar(a, b) output: 1 Suppose I want to merge two files, called mergeleft.csv and mergeright.csv Mergeleft.csv: ... (0 Replies)
Discussion started by: grossgermany
0 Replies

7. UNIX for Dummies Questions & Answers

file count with a twist

Hello Everyone, I am using the korn shell. I was hoping to find a set of commands to count files in a directory. I am using: ls /home/name/abc* | wc -l This command works fine when a file matches abc* (returns only the file count) , however when no file(s) are found I get... (2 Replies)
Discussion started by: robert4732
2 Replies

8. UNIX for Advanced & Expert Users

building a kernel (with a twist)

Hey all, I am working on a static analysis tool and I wan't to see if it can find bugs in the linux kernel, it uses LLVM framework to analyse the instructions. Long story short I need to build the kernel with a custom compiler. The compiler will create byte code files where binaries usually... (2 Replies)
Discussion started by: zigga15
2 Replies

9. UNIX for Dummies Questions & Answers

Suspending jobs (CTRL+Z) with a twist

Hi, Say for example I'm doing a very large scp transfer (which I am) and I keep stopping it with CTRL+Z because other people on my network need the bandwidth too. I can restart it no problem with fg but only if I dont reboot or anything in between. My question is... rather than stop/suspend a... (2 Replies)
Discussion started by: d11wtq
2 Replies

10. UNIX for Dummies Questions & Answers

how do I log into this machine - with a twist...

I know this topic has been covered in one form or another, but it hasn't been covered to handle my problem. I was given a Sparc4 running Solaris 2.5.1 The root password is unknown. This machine has no cdrom drive and it has no floppy drive. I tried booting into the single user mode, but... (1 Reply)
Discussion started by: xyyz
1 Replies
Login or Register to Ask a Question