For first question:
z is a string, the use of if block if(!(z in S)) is to check if z is an index of an element in Array S, just like what I've told above. If S has an element S["aa"], and z="aa", we say (z in S) is true,
so if(!(z in S)) condition is false.
p=p?RD A[i] : A[i]: this is a three meta compute.
Separate it to p= "p" ? "RD A[i]" : "A[i]"
the part between "equal to" and "question mark" is a expression, it can be true or false.
If it's true, p's value will be set to the part between "question mark" and "colon" in example "RD A[i]".
And if it is false, p's value will be set to the last part: "A[i]"
And, hah, found is also a array's name, not some special thing. In the code you'll find "found[++m]=z"
For second question:
When use gsub, use it like this to store the value in another variable.
len=gsub(......)
If you don't store it manually, it losts.
Hi Lucas_0418,
I think u can't get me.if s[5] is an array we can say that z takes values 0-4 but here how the array s is formed without any declaration and initializationand what are the values it's index takes.I know about working of conditional operator but what I wanted to know is way does it mean by p fieldspecifier A[i]
Sorry guy. I did get you.
array in awk doesn't need to initial, it is unadorn
Why if, it make sure S[z]'s value would only be set once.
Why
You know FS is field separator.
When s is not set, first time this code be executing.
s only need the content of A[i].
But after the first time, for separate pre value and a new A[i].
It use FS, that is why s=sFSA[i] for all times except the very first time
And, I am sorry for my mistake recently.
Last edited by Lucas_0418; 02-20-2014 at 01:26 AM..
Hi Lucas_0418,
can u just say a word what the if else block is doing and what for the end block is used.while analyzing this code I got to know if else is used for summing the fields of all lines which have got the same scope name where as end block will occur only at the end to print all the lines
Thanks,
preethy
---------- Post updated at 09:24 PM ---------- Previous update was at 08:48 PM ----------
Hi Lucas_0418,
finally what { print ; next }
!/Total/
it does is prints first line and recursively deletes all the lines containing total.But which line it will point aftet that.Plz provide me a clarification regarding replacing with x here in gsub
Hi preethy,
I am so sorry for my a lot of explanations that is not your expected.
And you have already got it ( For the use of if else block and the END block, your understanding totally right).
Now for
finally what {
The two sentences above are not relative.
Let us look at them in the total code.
{ print ; next } this would be executed only one time.(When NR==1, you also can say it the first line in 'file')
( print: print this line, it's equal to print $0 )
( next: do not execute the command after 'next' for current line, read next line, this is what you are asking, after this , it points to the second line. NR=2,
then back to beginning of the total code)
!/Total/{
...
}
If current line does not have a patter /Total/, step in the '{}' after the !/Total/.
After all, the meaning of gsub.
Assuming this line is
z = $3(z is set to "SRT-PKT-ActiveSubCPE-13")
gsub(/-[0-9]+$/,x,z) (Do you remember if a variable in awk has not been set,
the value of it is "", in this command, variable x is "",
"-13" is a /-[0-9]+$/ pattern, it would be substituted by ""(value of x )
so, after substitute, z is set to "SRT-PKT-ActiveSubCPE")
Hi lucas_0418,
for(k in S)
{
if(k == found[q])
{
}
}
k is "" here found[] consists all the values of z,how can if block gets executed if we are comparing null value to some string in found[].
Hope you dont feel like spoon feeding.
Thanks,
preethy
preethy and Lucas_0418 kindly use [CODE] tags and [ICODE] when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the code button in the editing menu. don't just discuss like chat.
kindly note this is a professional forum dedicated to the open and universal exchange of information. Please help keep the quality of the posts very high for the entire world community.
Hi,
I am totally a newbie to any programming languages and I just started an entry level job in an IT company. One of my recent tasks is to create a script that is able to show the log file of linux service (i.e. ntpd service)
lets say, if I run my script ./test.sh, the output should be... (3 Replies)
Dear Friends,
Please help me on this
my script name is send.csh
In this i have written the statement like this
set args = ( city state country price )
I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell
or
how to pass to... (2 Replies)
Dear Unix gurus,
We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Dear Unix gurus,
We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist.
diff=$1$2.diff
id=$2 new=new_$diff
echo "My id is $1"
echo "I want to sync for user account $id"
##awk command I am using is as below
cat $diff | awk... (2 Replies)
Hi All,
I have new for shell scripting.
Problem : I have one scrip at serv1 and path of server is /apps/dev/provimage/scripts and script name:extract_ancillary.bat.
I need to call this script at server2(my working server) and execute at server2 .
Please let me know how to build the... (5 Replies)
Hi,
I basically have 2 shell scripts.
One is a shell script will get the variable value from the user. The variable is nothing but the IP of the remote system.
Another shell script is a script that does the job of connecting to the remote system using ssh. This uses a expect utility in turn.
... (2 Replies)
i want use ssh on the host01 to execute autoexec.sh on the host02 like following :
host01> ssh host02 autoexec.sh
autoexec.sh include nohup command like follwing :
nohup /home/jack/deletedata.sh &
after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Hi,
I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input.
I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Hi Perl/UNIX experts,
I have a problem in running a shell script from my perl script (auto.pl).
I run the perl script using
perl auto.pl
from the shell prompt
The shell script picks the files in "input" folder and procesess it.
The shell script blue.sh has this code.
export... (16 Replies)