I have written the following shell script
the code is checking number of fields present and the value of first field. the number of fields can vary in data.csv. I wwant to move these variable and commands into one config file. some thing like this:
Config file:
by doing this I am able to get the value of variable but not output of unix commands
Last edited by rbatte1; 07-21-2016 at 07:51 AM..
Reason: Added CODE tags for config file
The sourcing of the config file with . ./config.cfg will read them in as you suspect, but it actually executes them so the values set will be for that one instance. If $line has no value at that point, then that is what you are asking it to process. Once only.
Perhaps you would be better to consider another way like this:-
Would that suit your purpose okay?
I hope that this helps and saves the performance costs of repetitive awk calls.
You could also use awk to process the files as a whole:-
...but I suppose it depends what you want to do with the values after this.
I'm not sure how to assess your code snippet. num_fields and field1 will hold meaningful values only if file has one single line only. Why, then, the while loop? With it, the two variables will hold the last line's values.
Please explain what exactly you want the config file to do.
It is not a bit strange to assume external resources in the config file.
E.g. use $line, hoping that $line exists in the calling script.
If you really want that, you should put the per-line code in a function
and ---------- Post updated at 14:02 ---------- Previous update was at 13:26 ----------
@rbatte1, the shell split differs from awk: a last empty field is not counted, $num_fields differs then.
Further, your code needs the delimiter
and protection from argument expansion with
If the positional parameters can be used then there is no need for an array, and this works even with old Bourne shells
Hi,
file1.txt
AAA
BBB
CCC
DDD
file2.txt
abc|AAA|AAAabcbcs|fnwufnq
bca|nwruqf|AAA|fwfwwefwef
fmimwe|BBB|fnqwufw|wufbqw
wcdbi|CCC|wefnwin|wfwwf
DDD|wabvfav|wqef|fwbwqfwfe
i need the count of rows of file1.txt present in the file2.txt
required output:
AAA 2 (10 Replies)
how to execute shell script present in unix machine remotely from windows?
I having a shell script in my unix machine, need to execute the script remotely from my windows machine using Visual Basic or VBA macros.
Thanks In Advance.
--Suresh (1 Reply)
Hi,
As a newbie, I'm desperate ro make my shell script work. I'd like a script which checks all the files in a directory, check the file name, if the file name ends with "extracted", store it in a variable, if it has a suffix of ".roi" stores in another variable. I'm going to use these two... (3 Replies)
Hello Experts,
I would like to know the best way to assign a value to variable from a given file and execute a command including this variable for each entry from the file. to be more clear, i have a file with different lines (each line with a different value). i want to substitute the variable... (2 Replies)
Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated.
script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made.
OS :Susi linux ver 10.3.
... (4 Replies)
Hi,
I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below.
I will be using the config file as mentioned below:
(config.txt)
country:a,b
city:1,2
type:b1... (1 Reply)
Hi there, am trying to parse an Apache 'server' config file. A snippet of the config file is shown below:
.....
ProxyPassReverse /foo http://foo.example.com/bar
.....
.....
RewriteRule ^/(.*) http://www.example.com/$1
RewriteRule /redirect https://www.example1.com/$1
........ (7 Replies)
Hi all,
I want to assign a command name to a file.e.g.
suppose I have a .sh file "xyz.sh". I want to execute the file by typing in "abc".
The desired output is:
$ abc
should execute the "xyz.sh" file.
Kind Regards,
Qasim (4 Replies)
Hello,
I know this is somewhat strange, but please let me know if possible. I want to execute a program file in the remote machine with command on the local machine. Let me make things more clear.
Suppose I have a cc on my local system and do not have that on the remote system. I want to use... (2 Replies)