Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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 have a config file that gives sub config files in this format:
-c config1 -c config2 -c config3 -c config4
I'm trying to read these files and do a simple check to see if specific text exists within these file (I know, I could cat the whole dir and grep it, but this is what I have in my head to accomplish this.....).
Anyway, I want to read in the file and split the sub config files out, to be processed in a loop. So I read in the main config, and from there awk out the sub-config files and process them in a loop. Can someone get me bumped in the right direction?
Thanks in advance. And no, this is not homework.
Getting them in an array would be easier because if you have confarray=(-c config1 -c config2 -c config3 -c config4), then you can get confarray=${confarray[@]//-c/}. If you're adamant you need to loop|awk, then why not while read; do case "$arg" in -c);; *) test -f $arg;; esac ?
Thanks for both replies. I plan on using this script on a couple different systems, so I'm not sure how many args will be on each machine. Maybe 1 on machine-a, and 13 on machine-b.
An array would be nice. I'm not stuck in any one form (other than a Bash script).
I want to finish a script that will read in the various sub-config file from the main config file. That way I can perform another action in the loop on the sub-config file. I have the rest of it pretty much done, just need to be able to read in the sub-configs for a loop purpose.
So I read in example.conf, which has the following in it:
-c sub1.conf -c sub2.conf -c sub3.conf -c sub4.conf
Now I want to perform (as an example):
perl -pi -e 's/what_you're_looking_for/what_change_to/' sub1.conf
perl -pi -e 's/what_you're_looking_for/what_change_to/' sub2.conf
perl -pi -e 's/what_you're_looking_for/what_change_to/' sub3.conf
Yeah, I did, thanks. I ended up just putting a variable in the head of the script:
CFGS="file1.conf file2.conf file3.conf" # and so on, depending on the machine
And then doing a loop based on that:
for process in ${CFGS} ; do
whatever()
done
And guess that'll have to work for now. I'd still like to know how to read that, though.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.