Sponsored Content
Full Discussion: awk loop issue
Top Forums Shell Programming and Scripting awk loop issue Post 302742043 by nsinha on Monday 10th of December 2012 12:19:46 PM
Old 12-10-2012
awk loop issue

Hi

I am not able to solve this minor issue even after a lot of trial! Will be thankful if you can help me out. This is part of a awk script and the loop is self-explanatory -

Code:
num_null_key=0			#for counting the number of null keys
num_non_null_key=0		#for counting the number of non null keys
while (key <= last_key)
{
        if ($key == "")
        {
                full_key = full_key " NULL"		#full_key will be concatenated
                if ($num_non_null_key == 0)	#this condition will be matched once
                	num_null_key++		#only when num_non_null_key=0
                printf("%d",num_null_key)
        }
        else
        {
                full_key = full_key " " key		#full_key will be concatenated
                num_non_null_key++		#so in the next loop the inner 'if' of the previous block will be tested
                non_null_key = non_null_key " " key #non_nulll_key will concatenated
                printf("%d",num_non_null_key)
        }
        key++
}

Suppose the complete key set is as follows - "12 " and so full_key should be "12 NULL NULL NULL NULL". But this is not happening. Also values of num_null_key and num_non_null_key are not getting populated correctly.

What is the actual mistake in my code?

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

for-while loop issue

sup experts..i had a script which was bugging me..was hoping someone could point out the issue here Input file: space separated 2 columns I wanted to print out the 2 columns after assigning them to variables ( bascially the same output but iterate through line by line ). The code worked... (7 Replies)
Discussion started by: foal_newbie
7 Replies

2. Shell Programming and Scripting

Issue with using While loop

Hi, I am trying to move a file from remote server to local server and when the transfer completes successfully i call a script in remote server to remove the file which was successfully transferred. I do this by first getting the list of file in remote server and move the text file to local... (8 Replies)
Discussion started by: funonnet
8 Replies

3. Shell Programming and Scripting

While loop with awk issue

Hi folks. I am trying to use a while loop along with awk to get the colums where 2 specific words are found. Here is the output of the command i run where i need to pull the column numbers if specific words are found: State Type Rebal Sector Block AU Total_MB Free_MB ... (3 Replies)
Discussion started by: Stephan
3 Replies

4. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

5. Shell Programming and Scripting

For loop, awk command issue

limit.csv data -------------- 5600050 38Nhava 400077 27Bomay rate.txt data ------------- 38NhaVA 27BomaY 27Bomay below is my script: for i in `cat limit.csv` do b=`awk '{print $1}' $i` (4 Replies)
Discussion started by: p_satyambabu
4 Replies

6. Shell Programming and Scripting

While Loop issue

Hi, i=0 t5=6000001 while do i=`expr $i + 1` t5=`expr $t5 + 1` echo $t5 done I am able to increment "col3" value but unable to get col1,col2 value. Input: t1=10001 t2=abc t3=ghkc (5 Replies)
Discussion started by: onesuri
5 Replies

7. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

8. Shell Programming and Scripting

awk - 2 files comparison without for loop - multi-line issue

Greetings Experts, I need to handle the views created over monthly retention tables for which every new table in YYYYMMDD format, there is equivalent view created and the older table which might be dropped, the view over it has to be re-created over a dummy table so that it doesn't fail.... (2 Replies)
Discussion started by: chill3chee
2 Replies

9. Shell Programming and Scripting

Issue with for loop

Hi Team, I have for loop in my shell script. Which basically loop through all files in the directory, When some files are in the directory it works just fine. But if there are no files at all..still the for loop try to execute. Please help. Below is the code. #!/bin/ksh echo "Program... (5 Replies)
Discussion started by: bharath561989
5 Replies

10. Shell Programming and Scripting

Issue in awk parsing under while loop

Hi I am trying to parse a grep output using awk. It works fine individually and not working under the loop with variable name assigned. cat > file.txt dict=/dictr/abcd/d1/wq:/dictr/abcd/d2/wq:/dictr/abcd/d3/wq: sample tried code Nos=`grep -w "dict" file.txt | awk -F"=" '{print... (10 Replies)
Discussion started by: ananan
10 Replies
K5SRVUTIL(1)						      General Commands Manual						      K5SRVUTIL(1)

NAME
k5srvutil - host key table (keytab) manipulation utility SYNOPSIS
k5srvutil operation [ -i ] [ -f filename ] DESCRIPTION
k5srvutil allows a system manager to list or change keys currently in his keytab or to add new keys to the keytab. Operation must be one of the following: list lists the keys in a keytab showing version number and principal name. change changes all the keys in the keytab to new randomly-generated keys, updating the keys in the Kerberos server's database to match by using the kadmin protocol. If a key's version number doesn't match the version number stored in the Kerberos server's data- base, then the operation will fail. The old keys are retained so that existing tickets continue to work. If the -i flag is given, k5srvutil will prompt for yes or no before changing each key. If the -k option is used, the old and new keys will be dis- played. delold Deletes keys that are not the most recent version from the keytab. This operation should be used some time after a change opera- tion to remove old keys. If the -i flag is used, then the program prompts the user whether the old keys associated with each principal should be removed. delete deletes particular keys in the keytab, interactively prompting for each key. In all cases, the default file used is /etc/krb5.keytab file unless this is overridden by the -f option. k5srvutil uses the kadmin program to edit the keytab in place. However, old keys are retained, so they are available in case of failure. SEE ALSO
kadmin(8), ktutil(8) K5SRVUTIL(1)
All times are GMT -4. The time now is 11:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy