AIX : Need help with <join> command in csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AIX : Need help with <join> command in csh
# 1  
Old 02-26-2011
Question AIX : Need help with <join> command in csh

Hi All,

I need your hand to resolve an issue I am facing with a join command in one of the script. Please see the 3 files attached where file1 and file2 are the two files I am passing to the join command written in the command file. Prior to calling the join I am also sorting both the files on the respective columns (1st column in file1 and 4th in the file2). But the join command is returning only one output instead of threeSmilie. You can simply download all the files in your home path and copy & paste commands from the command file on the standard prompt to see the output.
Could you please help me understanding what is stopping the other lines to display please ? If its a length related limitation with AIX join command than I would appreciate an alternative perl command or something suitable.

Regards - Sraj

Last edited by pludi; 02-26-2011 at 12:27 PM..
# 2  
Old 02-26-2011
Hi.

Printing the entire join yields 3 lines:
Code:
#!/usr/bin/env csh

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

echo
sort +1 -1 -t"|" file1.txt > data1
sort +4 -4 -t"|" file2.txt > 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 data1 data2

producing:
Code:
$ ./s1
 .cshrc invoked, version 2010.04.21.
aix 5.1.0.0
sort - ( /usr/bin/sort Oct 05 2004 )
join - ( /usr/bin/join Feb 10 2002 )
 
 10|3289924|2323234|45|45|01/12/2010|14:11|3115036|U|N|LPL|3115036|65Z|C|01/12/2010
 10|3289925|2323235|P81|P81|01/12/2010|14:12|3115036|U|N|LPL|3115036|65Z|C|01/12/2010
 10|3289926|2323236|900|900|01/12/2010|15:05|3115034|U|N|LPL|3115034|65Z|C|01/12/2010

The problem may have something to do with not printing field 4, but you'll need to experiment.

How are you counting fields?

Good luck ... cheers, drl
# 3  
Old 02-28-2011
Question

Thanks drl,

But its not displaying anything in my AIX 6.1 box though. Could you provide some AWK replacemnt of the join command. I did all possible experiment byt couldn't see anything.

Regards - Sraj

---------- Post updated at 11:55 AM ---------- Previous update was at 11:50 AM ----------

Thanks drl,

But its not displaying anything in my AIX 6.1 box though. Could you provide some AWK replacemnt of the join command. I did all possible experiment byt couldn't see anything.

Regards - Sraj
# 4  
Old 02-28-2011
Could this help you ?
Code:
awk -F"|" 'NR==FNR{a[$1]=$0;next}a[$5]{print a[$5]FS$0}' file1.txt file2.txt

This User Gave Thanks to pravin27 For This Post:
# 5  
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
# 6  
Old 03-01-2011
MySQL

Quote:
Originally Posted by pravin27
Could this help you ?
Code:
awk -F"|" 'NR==FNR{a[$1]=$0;next}a[$5]{print a[$5]FS$0}' file1.txt file2.txt

Hi Pravin,

Thanks you so much for the help. Its wored fine for me. I would appreciate if you can help me to undetstand the awk in detail please...

Thanks you once again

Regards - sraj
# 7  
Old 03-01-2011
Hi Sraj,
-F"|" = Input field separator
NR = This is the number of input records awk has processed since the beginning of the program's execution.
FNR= FNR is the current record number in the current file. FNR is incremented each time a new record is read . It is reinitialized to zero each time a new input file is started
Code:
awk -F"|" 'NR==FNR{a[$1]=$0;next}a[$5]{print a[$5]FS$0}' file1.txt file2.txt

It reads file1 first and fills up an array 'a', using fields 1 as key, $0 (i.e line or record) as value. When it then reads file2 it checks whether field 5 is in that array, if it is, print the array's contents, $0(i.e line or record) from file1.
This User Gave Thanks to pravin27 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question