Sponsored Content
Top Forums Shell Programming and Scripting AIX : Need help with <join> command in csh Post 302500358 by drl on Monday 28th of February 2011 10:05:46 AM
Old 02-28-2011
Hi.

Here is an amended version of my earlier script. I used bash so that I could easily highlight the fact that "P81" is not in the first file, and I changed the sort commands:
Code:
#!/usr/bin/env bash

# @(#)  s2      Demonstrate join.

# "version" is a local command, not generally available.
~/bin/version =o sort join

echo
if ! grep "P81" data1
then
  echo " Warning - no field matches P81 in data1." >&2
  echo " " >&2
fi
sort -b -k1,1 -t"|" file1.txt > data1
sort -b -k4,4 -t"|" file2.txt > data2
# join -t"|" -1 1 -2 4 data1 data2
# join -j1 1 -j2 5 -o 1.1 1.2 1.3 1.4 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 -t"|" file1.txt file2.txt
join -j1 1 -j2 4 -o 1.1 1.2 1.3 1.4 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 -t"|" data1 data2

producing:
Code:
$ ./s2
aix 5.1.0.0
sort - ( /usr/bin/sort Oct 05 2004 )
join - ( /usr/bin/join Feb 10 2002 )

 Warning - no field matches P81 in data1.
 
||||||||||||||||||
45|PATEL NAGAR|CD|LPL|10|3289924|2323234|45|45|01/12/2010|14:11|3115036|U|N|LPL|3115036|65Z|C|01/12/2010
900|LORD'S FAVOUR CC|CD|LPL|10|3289926|2323236|900|900|01/12/2010|15:05|3115034|U|N|LPL|3115034|65Z|C|01/12/2010

So we expect and get 2 data lines and one line of separators. It looks like the "j" is not necessary (in 5.1.0.0), but join does not seem to care.

Good luck ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

join command

Hi, I'm using the join command and it appears to discard certain fields. Here are the two files i'm comparing: File1: 1 a 2 b 3 c 4 d 99 f 101 g 999 i 200 j File 2: 1 e 2 f 3 g 4 h 99 h (22 Replies)
Discussion started by: penfold
22 Replies

2. Shell Programming and Scripting

problen with a join under AIX

Hello, I have a script shell under aix with a join of 2 files fic2.txt : test100:zone 1 :zone 2:zone 3 test10:zone 1:zone 2:zone 3 test:zone 1:zone 2:zone 3 fic3.txt: test100:zone 4:zone 5 test10:zone 4:zone 5 test:zone 4: zone 5 and the command : join -11 -21 -t: fic2.txt... (4 Replies)
Discussion started by: tbeghain
4 Replies

3. Shell Programming and Scripting

csh -f and the at command

Hi everyone. I am new to the forums and new to Unix, so please pardon my beginner "status". In my company, we have a few C shell scripts, which we call BAT files (!). They all start with the usual "#/bin/csh" line to get it to run the .cshrc script which preloads the session with a lot of... (1 Reply)
Discussion started by: SpanishPassion
1 Replies

4. Shell Programming and Scripting

join (pls help on join command)

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

5. Shell Programming and Scripting

awk command for simple join command but based on 2 columns

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

6. Shell Programming and Scripting

Help me fixing event handling in csh on AIX

Hi All, I have problem with a csh script. This script simply search for a certail process id and kill that using simple kill -5 <pid>. Everything is okay untill there is valid process id trapped. But if the process id is already cleaned before the execution of the kill command, but script ends... (2 Replies)
Discussion started by: sraj142
2 Replies

7. UNIX for Dummies Questions & Answers

how to join two files using "Join" command with one common field in this problem?

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

How to use the the join command to join multiple files by a common column

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

String operation in csh AIX 4.3.2.0

Hi to everybody i stuck on a simple thing i had a string and i want cut it , i try already few thing with the cut command but does not the way it should. The script is in csh and running on AIX 4.3.2.0 here are few samples how the string can look like FT71;1;1;1;;;1;31.01.2017... (9 Replies)
Discussion started by: Nadielosabra
9 Replies

10. UNIX for Beginners Questions & Answers

If command in csh

hi everyone what is difference between "if ( -e Arch )" and "if ( -e ./Arch )" in csh shell? Many Thanks samad (1 Reply)
Discussion started by: abdossamad2003
1 Replies
JOIN(1) 						      General Commands Manual							   JOIN(1)

NAME
join - relational database operator SYNOPSIS
join [ options ] file1 file2 DESCRIPTION
Join forms, on the standard output, a join of the two relations specified by the lines of file1 and file2. If file1 is `-', the standard input is used. File1 and file2 must be sorted in increasing ASCII collating sequence on the fields on which they are to be joined, normally the first in each line. There is one line in the output for each pair of lines in file1 and file2 that have identical join fields. The output line normally con- sists of the common field, then the rest of the line from file1, then the rest of the line from file2. Fields are normally separated by blank, tab or newline. In this case, multiple separators count as one, and leading separators are dis- carded. These options are recognized: -an In addition to the normal output, produce a line for each unpairable line in file n, where n is 1 or 2. -e s Replace empty output fields by string s. -jn m Join on the mth field of file n. If n is missing, use the mth field in each file. -o list Each output line comprises the fields specified in list, each element of which has the form n.m, where n is a file number and m is a field number. -tc Use character c as a separator (tab character). Every appearance of c in a line is significant. SEE ALSO
sort(1), comm(1), awk(1) BUGS
With default field separation, the collating sequence is that of sort -b; with -t, the sequence is that of a plain sort. The conventions of join, sort, comm, uniq, look and awk(1) are wildly incongruous. 7th Edition April 29, 1985 JOIN(1)
All times are GMT -4. The time now is 02:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy