LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-24-2012, 02:48 AM   #1
gilad73
LQ Newbie
 
Registered: Jun 2012
Posts: 8

Rep: Reputation: Disabled
Trouble with script


Hi,

I am having a problem with a script I am writing. It is a simple kind of script which joins a few files, spits out a csv file and then I call a perl script to convert it to html.

The following 3 lines are giving me trouble:
#I know I could do the sort all in the join line - but I find this more readable
sort -t, -k2 /tmp/proxmox/nmap_net0_join > /tmp/proxmox/sorted_nmap_net0_join
sort -t, -k1 /tmp/proxmox/qmlist | sed 's/ /,/g' > /tmp/proxmox/sorted_qmlist
join -t, -11 -22 /tmp/proxmox/sorted_qmlist /tmp/proxmox/sorted_nmap_net0_join >/tmp/proxmox/statusinfo 2>/tmp/proxmox/log

If I execute each line individually in a command prompt the statusinfo file is generated correctly. However if I execute the script I get a "join: file 1 is not in sorted order" exception in the log. What am I missing?
 
Old 07-24-2012, 05:16 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
If your script has just those 3 lines, then there should not be any difference from running the 3 lines manually. (Easy to try it...) My guess is that the issue is with something else in the script.
 
Old 07-24-2012, 05:48 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you can try to run your script with -x (bash -x <srcipt>) and check the output
 
1 members found this post helpful.
Old 07-24-2012, 06:35 AM   #4
gilad73
LQ Newbie
 
Registered: Jun 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
The bash -x option was new for me. I haven't solved the problem yet, but now I have more info to work with. I will sprinkle the script with echos and other output so I know what is happening at that stage.

Thanks!
 
Old 07-25-2012, 08:43 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try bash -xv or
Code:
#/bin/bash
set -xv
at the top of the script itself and just call it direct
Code:
./myscript.sh
 
Old 07-26-2012, 01:40 AM   #6
gilad73
LQ Newbie
 
Registered: Jun 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Thanks Chris! I actually did set it in my script "#!/bin/bash -vx" and that worked fine. Still not working as expected though. Maybe let me explain my issue again.

Let's say I have 2 files:
file1:
234,up
235,up
236,down
237,up
238,down
239,up

file2:
AB,34X,236
BB,36N,237
AC,56X,238
DB,39X,239
EC,39L,240
FR,19M,241
NH,99P,242
EN,21Q,242

I want to join them on the first col of file1 and 3rd of file2 (even if there is no match) and have output like this:

234,up,NA,NA
235,up,NA,NA
236,down,AB,34X
237,up,BB,36N
238,down,AC,56X
239,up,DB,39X
240,NA,EC,39L
241,NA,NH,99P
242,NA,EN,21Q

(NA where there is no matching data). I have tried with simple left and right joins (using -a and -e options) as well as initial g/awk attempts (don't really graps awk yet). not working as expected yet. Any thoughts?
 
Old 07-26-2012, 08:30 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
The idea of the -xv was to see what was causing the error reported in your first post.
Just run it with those cmds in a script and post the results; we can't guess, we need to see what you see,
 
Old 07-26-2012, 09:48 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
From an awk point of view:

1. Read first file into an array with field one as index (this of course assumes that it will not be overwritten, ie all field one entries are uniq)

2. Search file two and compare indexes to third field, from here you have two sub options

a. Print data in format required

b. Append data to array at index

Part 'b' the requires you to output the array in the END clause, but the benefit here is you can then sort it by the indexes so they appear
in numerical order.

Here is a good awk reference. if you need further help let us know?
 
Old 07-30-2012, 05:57 AM   #9
gilad73
LQ Newbie
 
Registered: Jun 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Chris and Grail - thanks for the help. I got too busy in the past few days with other issues. Hope to have more time to try your advice soon.

Thanks!
Gilad
 
  


Reply

Tags
bash, join, sort



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert ksh script into bsh script trouble dan-e Linux - Newbie 1 05-09-2011 01:11 AM
[SOLVED] Elementary Script Trouble mwesolow Linux - Newbie 7 09-20-2010 12:55 AM
Trouble with script and bc Freestone Linux - General 4 10-11-2006 06:10 PM
Trouble in Shell Script Gerardoj Linux - General 6 12-02-2003 09:21 PM
imwheel and script trouble Toker Linux - General 8 10-06-2003 02:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration