However, I am curious to know why this does not work
I have told you above that "eval" is a command. Take another command, for example "ls", and ask yourself if you expect
to work. You are aware that -v"REP=<something>" is a declaration of a variable, aren't you? It declares "REP" to hold a certain value inside awk. Would you expect "$x" here:
to hold a directory listing or rather the string "ls", hmm?
/PS: Is there any reason why you introduce an element "NULL" in every array which you do not use at all?
I could have the following
But I would like to simplify the whole thing. That's why I was wondering if there was anyway to use a double nested loop
This is not working either
but this works
But I would like to simplify the whole thing. That's why I was wondering if there was anyway to use a double nested loop
Good idea.
This is not working either
Quote:
Originally Posted by Xterra
Later on you reference these three arrays as:
Lets put aside the business with awk and the eval for a moment. ${TMPArray[$y][$e]} is supposed to be a two-dimensional array, a matrix, yes? The two variables "$y" and "$e" should hold row and column, correct?
Now look again at how you defined your arrays: this is not one two-dimensional array (like the one i sketched out for your above, in ksh), but its three one-dimensional arrays which just happen to have similar names.
Let us simplify our requirements for a moment. Instead of using complex parameter-passing calls to awk we simply want to print the content of the arrays using a nested loop to generate the indexes. We also simplify the contents of the arrays:
Now let us construct the outer loop. This one should generate the names of the arrays:
You are still with me? Good, now for the second, inner loop to count the colums. Notice that array elements are numbered starting with 0, not 1, therefore we let the for-loop run from 0-2, not 1-3. This way we do not need a NULL element which we would ignore.
Notice that this outputs the names of the variables correctly. But we do not want the names, we want the contents. This is why we restart the process of substituting a variables name with its content a second time. We put an "eval" in front of the command and a (protected by a "\") "$"
The only thing left to explain is why the "$" had to be protected: well, picture how the process of substituting variables names with their contents happens:
The "$" had to be protected so that it would not be translated in the first processing pass.
If you could tell us WHAT doesn't work? On first sight I can comment that you're using parentheses instead of braces for the REP assignment.
Sorry, I meant to use braces. Still, that does not work. The outfiles are empty which makes me think I am not assigning the variable replacement correctly.
Hello,
Below I try to control that the input is good an IP :
#!/bin/bash
cp /home/scripts/choice_interfaces.txt /home/scripts/interfaces.txt
chmod 644 /home/scripts/interfaces.txt
echo -e "Please enter the network informations into the /etc/network/interfaces file, complete them below... (9 Replies)
I have a below syntax its working fine...
var12=$(ps -ef | grep apache | awk '{print $2,$4}')
Im getting expected output as below:
printf "%b\n" "${VAR12}"
dell 123
dell 456
dell 457
Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Hi All,
I've been researching this problem and I am pretty sure that the issue is related to the while loop and the piping. There are plenty of other threads about this issue that recommend removing the pipe and using redirection. However, I haven't been able to get it working using the ssh and... (1 Reply)
Hi,
I've a requirement where I want to re-assign the value in the variable through which FOR LOOP loops.
For e.g.
Snippet of code
---------------
for i in $var
do
echo $i >> $tempFile
var=`echo $another_var | awk -F" " '{print $1}'`
done
I am re-assigning var so... (2 Replies)
I have tried everything I can think of to get sed to change line N of a file to the contents of a variable. I have Googled the Internet, and I find lots of people telling how to use variables with the "Substitute" command, but no one telling how to use variables with the "Change" command.
I... (4 Replies)
Hi, I need some help to figure out why an outer for loop KSH variable does not decode in AWK but inner for loop does. Below is my code,
If I hard code variable 'SUBSEQ' in AWK it works but if I try to pass the SUBSEQ from KSH, it does not and when I pass the variable 'NAM' from KSH it works: I... (1 Reply)
I want to instert Category:XXXXX into the 2. line
something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong:
sed "2i\\${n}Category:$cat\n"
Sample:
Titel Blahh Blahh abllk sdhsd sjdhf
Blahh Blah Blahh
Blahh
Should look like... (2 Replies)
Surely there's an easier way to do this, lets see if anyone knows! I am new to scripting so go easy on me!
I have the following script and at the moment it doesn't work and I believe the problem is that I am using a while loop within a while loop. When I run the script using sh -x I can see... (6 Replies)
Can I use search & replace in any variable?
Suppose I have one variable named var1 which holds value "abcabc" I need to search 'a' in var1 and want to replace with 'x' like 'xbcxbc'. Is it possible? Can you provide me an example?
Malay (3 Replies)
Hi,
I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares.
For example:
file1 has a list of user ids (about 900) from the company's e-mail server.
file2 has a list of user ids (about 50 or so) from... (7 Replies)