Linux - NewbieThis 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.
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.
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?
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.
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 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
(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?
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,
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.