05-19-2009
join command and delimiters
I am using the join command to join information from two files that have a common field. Here are some examples:
field1:
99900 543
99903 333
99998 120
10000 222
100001 333
100005 220
field2:
99900 2009-05
99903 2009-05
99998 2009-05
100000 2009-05
100001 2009-05
100005 2009-05
I use the command like this:
join -t " " file1 file2 |sort -un > file3
The result is this:
99900 543 2009-05
99903 333 2009-05
99998 120 2009-05
It seems to stop when it gets to 100000.
So, I tried this:
join file1 file2 |sort -un > file3
I get the same result.
I assume that the default delimiter is white space, no matter how many, so the latter command should work. The former command denotes one space, which is not true, since it actually is two spaces.
So, I am confused as to why this works fine up to 99998, but will go no further.
9 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
I am trying to join 2 files..viz
f1:
12~a1
13~a2
112~a3
1112~a4
f2:
12~fa2
13~fa2
112~fa3
1112~fa4
while I join..I just get 2 o/p..
12~a1~fa2
13~a2~fa2 (4 Replies)
Discussion started by: unisam
4 Replies
2. Shell Programming and Scripting
Greetings,
I am attempting to use the join command to produce a file from 2 sorted comma seperated files. Ex.:
FILE 1:
jane,dow
joe,blow
FILE 2:
jane,dow,50,50,20
joe,blow,29,53,25
spike,lee,50,91,05
I want the resulting file to be reconds in FILE 2 where the person exists in FILE... (4 Replies)
Discussion started by: Supial
4 Replies
3. Shell Programming and Scripting
Hi,
I am a new learner of join command. Some result really make me confused.
Please kindly help me.
input:
file1:
LEO oracle engineer 210375
P.Jones Office Runner ID897
L.Clip Personl Chief ID982
S.Round UNIX admin ID6
file2:
Dept2C ID897 6 years
Dept5Z ID982 1 year
Dept3S ID6 2... (1 Reply)
Discussion started by: summer_cherry
1 Replies
4. Shell Programming and Scripting
Hi
my problem is:
I've 2 files like:
file1:
file2
I'd like to get file_out:
I mean if the field is different from zero in the first file i want take that field also in the second(no matter if in the second is zero).
I tried with the join command but it doesn't work always and i don't... (2 Replies)
Discussion started by: Dedalus
2 Replies
5. Shell Programming and Scripting
Hello,
I am using join to merge two files together. The defaults usually works great
join file1 file2 However, sometimes file1 or file2 has more keys, which I want to keep.
file 1:
-1 z
0 a
1 b
2 c
file 2:
0 a2
1 b2
2 c2
3 c3
So I do
join -a1 -a2 file1 file2 But then you don't... (0 Replies)
Discussion started by: ayu
0 Replies
6. Shell Programming and Scripting
input1
a_a a/a 10 100
a1 a_a 20 200
b1 b_b 30 300
input2
a_a a/a xxx yyy
a1 a1 lll ppp
b1 b_b kkk ooo
output
a_a a/a 10 100 xxx yyy (2 Replies)
Discussion started by: ruby_sgp
2 Replies
7. UNIX for Dummies Questions & Answers
file1:
Toronto:12439755:1076359:July 1, 1867:6
Quebec City:7560592:1542056:July 1, 1867:5
Halifax:938134:55284:July 1, 1867:4
Fredericton:751400:72908:July 1, 1867:3
Winnipeg:1170300:647797:July 15, 1870:7
Victoria:4168123:944735:July 20, 1871:10
Charlottetown:137900:5660:July 1, 1873:2... (2 Replies)
Discussion started by: mindfreak
2 Replies
8. UNIX for Dummies Questions & Answers
Hi,
I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column).
I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies
9. Shell Programming and Scripting
Hello All,
I am trying to join two files, each with differing delimiters. file1 has
doe, john 10.00 60.00 4.00 5.00
doe, jane 10.00 60.00 4.00 5.00
...while file2 has the following content:
doe, johnz 10.00::60.00:4.00:5.00
doe, janet 10.00:60.00::4.00:5.00
Currently, I have join... (2 Replies)
Discussion started by: techieg
2 Replies
merge(1) General Commands Manual merge(1)
NAME
merge - three-way file merge
SYNOPSIS
file1 file2 file3
DESCRIPTION
combines two files that are revisions of a single original file. The original file is file2, and the revised files are file1 and file3.
identifies all changes that lead from file2 to file3 and from file2 to file1, then deposits the merged text into file1. If the option is
used, the result goes to standard output instead of file1.
An overlap occurs if both file1 and file3 have changes in the same place. prints how many overlaps occurred, and includes both alterna-
tives in the result. The alternatives are delimited as follows:
lines in file1
lines in file3
If there are overlaps, edit the result in file1 and delete one of the alternatives.
This command is particularly useful for revision control, especially if file1 and file3 are the ends of two branches that have file2 as a
common ancestor.
EXAMPLES
A typical use for is as follows:
1. To merge an RCS branch into the trunk, first check out the three different versions from RCS (see co(1)) and rename them for
their revision numbers: 5.2, 5.11, and 5.2.3.3. File 5.2.3.3 is the end of an RCS branch that split off the trunk at file 5.2.
2. For this example, assume file 5.11 is the latest version on the trunk, and is also a revision of the "original" file, 5.2.
Merge the branch into the trunk with the command:
3. File 5.11 now contains all changes made on the branch and the trunk, and has markings in the file to show all overlapping
changes.
4. Edit file 5.11 to correct the overlaps, then use the command to check the file back in (see ci(1)).
WARNINGS
uses the ed(1) system editor. Therefore, the file size limits of ed(1) apply to
AUTHOR
was developed by Walter F. Tichy.
SEE ALSO
diff3(1), diff(1), rcsmerge(1), co(1).
merge(1)