This should be a simple script (and it would be nice if it worked)
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.
This should be a simple script (and it would be nice if it worked)
Pardon me if I am taking the MVS JCL approach to building this script (I have only known 3 persons who COULD write JCL from scratch and only one who WOULD do so. The normal approach was to take someone else's script and modify it :-).
I have a bunch of files which were split with HJ Split or something similar. I have found and installed lxsplit which allows me to join them from the command line thusly:
lxsplit -j mysplitfile.001
where the .001 file is the first in the set. Works great except I have a number of files to join and they have spaces in the names. So I pulled out a little script which vacuums or compacts Firefox database files as a starting example.
Quote:
for i in *.sqlite; do echo "VACUUM;" | sqlite3 $i ; done
I modified it thusly
Quote:
for i in *.001; do echo "lxsplit -j" \"$i\" ; done
This in fact displays the proper commands to the terminal. However, it does not execute them.
Quote:
[ken@taylor12 numbered]$ for i in *.001; do echo "lxsplit -j" \"$i\" ; done
lxsplit -j "my first file.djvu.001"
lxsplit -j "my second file.pdf.001"
lxsplit -j "my third file.djvu.001"
If I direct the output to a file and execute it as a script it performs the desired joins. The question is... How do I make the script execute the desired commands in the terminal?
The first script pipes the command VACUUM to the sqlite program. In my case I am not executing any commands within lxsplit. I am simply running the program with a couple of arguments. I tried this
Quote:
[ken@taylor12 numbered]$ for i in *.001; do lxsplit -j < \"$i\" ; done
bash: \"$i\": ambiguous redirect
but no luck. Same error without the escaped quotes. Finally I tried
Quote:
for i in *.001; do lxsplit -j echo \"$i\" ; done
which produced no errors but also did nothing.
I am obviously missing something simple. Can anyone please clue me in?
for i in *.001; do echo "lxsplit -j" \"$i\" ; done
I'm not a bash scripting guru but this is not supposed to execute lxsplit: it will run the echo command with your string as an argument.
Quote:
Originally Posted by taylorkh
for i in *.001; do lxsplit -j echo \"$i\" ; done
Here you are passing the echo command as an argument to lxsplit, which I don't think is supposed to work either.
I have never used lxsplit, but according to the project homepage this is how the syntax should be, in order to merge the split pieces into the original file:
I believe the " in the file name confused things - removing the escaping will allow the scanner to do it thing (which removes the " characters) leaving just the file name.
When you were testing, the part '...do echo "lxsplit -j" \"$i\" ' had proper escaping for embedding a " in the output... but you then removed the echo and the quotes around the lxsplilt -j.. but forgot to also remove the escape from the rest.
I also missed the erroneous redirect... (sorry about that)
Last edited by jpollard; 07-17-2013 at 09:50 AM.
Reason: I had a booboo.. pointed out by the earlier post.
Thanks Firerat, that did the trick. If I might impose on you for a little help in understanding...
The find command I understand. The exec part I think I understand and {} must be passing the name of the file to lxsplit. What I do not understand is how/why this loops through all of the found files in the directory. Does the -exec cause the command to be executed for each result of the find command?
All of the IFS stuff is unnecessary, a bure bash solution was already posted earlier by jpollard:
Code:
for i in *.001; do lxsplit -j "$i" ; done
"for i in *" handles spaces just fine, and the quotes around $i in the lxsplit call keep it from splitting there. "find" works, but is grossly overkill for this problem. A --maxdepth=1 parameters should be added in the find command as well to keep it from diving into subdirectories (assuming that behavior is not desired).
Last edited by suicidaleggroll; 07-17-2013 at 12:53 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.