Read variables from a text file in Bash
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. :) |
Actually, if there are less than 10 of these tags, you can do it easily:
Code:
file1="cat MainConfig | gawk -F' -c ' '{print $1}'" Hope this helps LinX |
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 And so on. Thanks again! |
Check these out if you didn't already:
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html http://www.tldp.org/LDP/abs/html/ |
Quote:
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. |
All times are GMT -5. The time now is 07:29 AM. |