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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-24-2012, 02:48 AM
|
#1
|
LQ Newbie
Registered: Jun 2012
Posts: 8
Rep: 
|
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?
|
|
|
07-24-2012, 05:16 AM
|
#2
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
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.
|
|
|
07-24-2012, 05:48 AM
|
#3
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,991
|
you can try to run your script with -x (bash -x <srcipt>) and check the output
|
|
1 members found this post helpful.
|
07-24-2012, 06:35 AM
|
#4
|
LQ Newbie
Registered: Jun 2012
Posts: 8
Original Poster
Rep: 
|
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!
|
|
|
07-25-2012, 08:43 PM
|
#5
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,430
|
Try bash -xv or
at the top of the script itself and just call it direct
|
|
|
07-26-2012, 01:40 AM
|
#6
|
LQ Newbie
Registered: Jun 2012
Posts: 8
Original Poster
Rep: 
|
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?
|
|
|
07-26-2012, 08:30 PM
|
#7
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,430
|
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,
|
|
|
07-26-2012, 09:48 PM
|
#8
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,035
|
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?
|
|
|
07-30-2012, 05:57 AM
|
#9
|
LQ Newbie
Registered: Jun 2012
Posts: 8
Original Poster
Rep: 
|
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
|
|
|
All times are GMT -5. The time now is 04:58 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|