ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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 would like to use the command ls -R to search for files in various directories but I need an absolute path so as I can use the results in additional script.
I've had a look through the man pages but can't find anything on the subject, could anyone shed some light on this one for a newbie?
the files im searching for are in subdirectories of the pwd and the results are being used with grep as in
Code:
ls -R | grep "001.jpg"
for more info on the main application im working on see the thread 'Populating array in a "for .. in .." loop' lower down on this page - (sorry I can't link until I've posted 5 times)
Thanks for all the feedback, the script works great with your help. But now im thinking of trying to recreate it using C, would anyone consider this to be better than using BASH?
It does call a java program to combine PDFs, would this cause a problem?
Code:
#!/bin/bash/
# This program combines multiple PDFs into a single multipage pdf
filedir=~/Desktop/Process/; #text input files here
workdir=~/Desktop/OnlinePDF/; #single pdf pages here
workfile=$1; #name of text file passed at command
filename="$workfile"_`date +%h%d_%H%M`; #name of output file
cd $workdir;
myfiles=( $(cat $filedir$workfile | while read part; do find . | grep $part; done ) );
#java program to combine pdf pages
joinPDF $filename.pdf ${myfiles[*]};
exit 0
It wouldn't cause a problem... but does it really make sense,
considering that most of the CPU cycles are going to be spent
on Java, anyway? I don't think you'd gain much performance,
since the majority of the actual processing in the bash-script
won't be the loop but a) the highly optimized find & grep (I
doubt that you'll write more efficient C code) and b) the chubby
java ... ;}
Thanks for the tips, I am only getting to grips with c and am treating the program as an exercise (although it does do an important job of saving me precious time at work!). My main reasoning for using c is to build in error checking and a user interface for my collegues who are command line shy and only use GUI's.
Good idea to implement it completely in C then, as calling system() means creating a new process env each time. Big overhead if you are calling within a loop.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.