Bash join script not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash join script not working
# 1  
Old 11-29-2011
Bash join script not working

So i'm currently working on a project where I'm attempting to display information of users from the /etc/passwd file and also another information file holding addition information about users.

Problem is I've been trying to join the two files together and have all of the information about each user in 1 file on 1 line for each user but it doesn't want to work for me.
Both files are delimited by colons.

note: information here is made-up .

Code:
$cat AdditionalInfo
 Usr1:Jill Smith:123 Sunset Avenue:1990:2001
 Usr2:Jack Bloggs:321 Sunrise Street:1989:2010
 ect....

/etc/passwd has lots more users than the few that are in the Additional information file and i only need the info from /etc/passwd for those records.

So far all my attempts of joining the files end with either no output, or only the output from the additionalinfo file.

Code:
$join -t: AdditionalInfo /etc/passwd

gives nothing.

if anyone knows why this doesn't work and can offer a solution it would be greatly appreciated.

Desired output would be

Usr1:Jill@mail.com:123 Sunset Avenue:1990:2001:x:1000:1000:Jill Smith:/home/admin/Usr1:/bin/bash
Usr2:Jack@mail.com:321 Sunrise Street:1989:2010:x:1001:1001:Jack Bloggs:/home/admin/Usr2:/bin/bash
-

Last edited by Nostyx; 11-29-2011 at 04:32 PM.. Reason: desired output.
# 2  
Old 11-29-2011
join works with sorted files.
therefore, both must be sorted prior to the 'join' command.

you may sort to new filenames prior to the 'join', or try to sort in-line
i would recommend sorting to new filenames first.
This User Gave Thanks to joeyg For This Post:
# 3  
Old 11-29-2011
Update:

Code:
$sort -t: -k1 AdditionalInfo > AdditionalInfo.srt
$sort -t: -k1 /etc/passwd > etcpasswd.srt
$join -t: AdditionalInfo.srt etcpasswd.srt

Joins the matching fields correctly thanks.
Literally figured it out as you were posting Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Best way to get a bash script working in C

Ahoy friends. Currently i got a bash script running to manage my minecraft servers. All of them are stored in /home/minecraft_servers directory. Using my script im able to start a server (e.g. ./minecraft start ftb_continuum) because server name and server name are the same.(e.g.... (2 Replies)
Discussion started by: Knogle
2 Replies

2. Shell Programming and Scripting

Aliases NOT working inside bash shell script

i have defined a function ln_s() for customizing the ln command in script1.sh. more script1.sh echo "Starting Execution" ./script2.sh echo "End of Execution" ln_s(){ ] && return ln -s "$1" "$2" } My script1.sh executes another script2.sh which has the following entry more script2.sh... (12 Replies)
Discussion started by: mohtashims
12 Replies

3. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

4. UNIX for Dummies Questions & Answers

Join not working

Hi all, I'm trying to use the join command to merge two files, but it's not finding lots of the matches. I have three files in total: File A: 31_77 34_46 72_61 85_10 85_23 110_33 144_45 154_25 154_90 170_5 170_44 217_63 255_19 333_20 333_23 333_32 (2 Replies)
Discussion started by: HEP
2 Replies

5. Shell Programming and Scripting

Join not working for comparision

Hi All, I have 2 files where the first column of both the files have to be compared and if they match the first six columns of the first file to be extracted in the output file. Format of files : File1 : ${SHTEMP}NPBR5.XTR.tmp S00016678|129|7|MPF|20090106|E... (3 Replies)
Discussion started by: nua7
3 Replies

6. Shell Programming and Scripting

sed not working in a bash script

Hi friends, I have two files - input and commands I want to read the input and replace a value in it with the contents in commands. My script is like this. Instead of printing the value in the commands file, it is simply printing $cmd in the output file. Any pointers are highly... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

7. Shell Programming and Scripting

bash script for ftp-upload is not working

Hello everyone, sorry for the title, most of you must getting sick of reading something like this, but I haven't found a solution, although I found many threads according to it. I'm working on a bash script that connects to a network printer with ftp where I want to upload a pdf created... (3 Replies)
Discussion started by: le_mae
3 Replies

8. Shell Programming and Scripting

Moving old files bash script - not working properly

I'm trying to write a script that moves data that's older than 2 weeks to a different place. It works well, EXCEPT, that when the script hits a file within a directory inside the working directory, it will move it to the root of the destination directory instead of putting it in the correct... (1 Reply)
Discussion started by: ugolee
1 Replies

9. Shell Programming and Scripting

Simple BASH script not working?

So I need a script that does the following: If a certain user is logged in Run `command` Else Echo “incorrect user” This is my first stab...which doesn't work: #!/bin/bash X="user=`ls -l /dev/console | cut -d " " -f 4`" Y="foobar" echo $X echo $Y (4 Replies)
Discussion started by: doubleminus
4 Replies

10. UNIX for Dummies Questions & Answers

join not working

I was trying to merge the following two example files using their first field: join -1 1 -2 1 file1 file 2 but nothing is produced. The expected result should be: rs1005152 7 q21.3 3 It appears that the length of the first field in file1 is causing the problem. Any suggesting on how to... (12 Replies)
Discussion started by: gamma_user
12 Replies
Login or Register to Ask a Question