Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script
# 22  
Old 02-19-2014
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.

I'm so sleepy, going to sleep now, bye!!
# 23  
Old 02-19-2014
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]

Thanks,
preethy
# 24  
Old 02-19-2014
Sorry guy. I did get you.
array in awk doesn't need to initial, it is unadorn
Code:
if(!(z in S)){
 S[z] = $0

Why if, it make sure S[z]'s value would only be set once.

Why
Code:
s= "s" ? "s FS A[i]" : "A[i]"

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 12:26 AM..
# 25  
Old 02-19-2014
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

Thanks,
preethy
# 26  
Old 02-19-2014
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 {
Code:
 print ; next } 
!/Total/

The two sentences above are not relative.

Let us look at them in the total code.
Code:
NR == 1 { print ; next } 
                 !/Total/{
					  z = $3
					  gsub(/-[0-9]+$/,x,z)
			  if(!(z in S)){
					    ...
				       }
				  else {
						... 
				       }				
			  }

{ 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
Code:
20131203170000,171.99.192.0/23,SRT-PKT-ActiveSubCPE-13,87,509,0,66,399,44,0,0,0,0,0,0,"

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")
# 27  
Old 02-19-2014
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
# 28  
Old 02-20-2014
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.

Thanks,

Regards,
Akshay
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script newbie- how to generate service log from shell script

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)
Discussion started by: xiaogeji
3 Replies

2. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

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)
Discussion started by: SA_Palani
2 Replies

3. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

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)
Discussion started by: dba1981
1 Replies

4. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

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)
Discussion started by: dba1981
1 Replies

5. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

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)
Discussion started by: Ashunayak
2 Replies

6. Shell Programming and Scripting

Correct shell script to Call One shell script from another shell script

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)
Discussion started by: Vineeta Nigam
5 Replies

7. Shell Programming and Scripting

call another shell script and pass parameters to that shell script

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)
Discussion started by: sunrexstar
2 Replies

8. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

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)
Discussion started by: orablue
1 Replies

9. Shell Programming and Scripting

invoking a shell script inside cgi shell script

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)
Discussion started by: smriti_shridhar
2 Replies

10. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

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)
Discussion started by: hifake
16 Replies
Login or Register to Ask a Question