Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Just need some guidance on this nawk Post 302827485 by newbie_01 on Friday 28th of June 2013 09:04:42 PM
Old 06-28-2013
Just need some guidance on this nawk

Hi,

I am trying to debug some KSH script and it has the nawk portion below. I just want to confirm whether I understand what it does correctly.

Example usage of the nawk line is run as below:

Code:
 
nawk '/^#/ {next}
$1~/^'testp.cfg'$|^'testp.cfg'\.testdb\.com\.ph$/ {
   c=0
   while (getline) {
     gsub (" ","")
     s=tolower($0)
     if (s~/host=/) {
        sub("^.*host=","",s)
        sub("\\\).*","",s)
        print s
        exit
     }
     c++
     if (c>20) {exit}
   }
}' $TNSNAMES

$TNSNAMES is a tnsnames.ora file, excerpts of some of its lines as below:

Code:
 
testd.testdb.com.ph = 
  (DESCRIPTION = 
        (ADDRESS = 
          (COMMUNITY = tcpip.world)
          (PROTOCOL = TCP)
          (Host = testd.testdb.com.ph)
          (Port = 25036)
        )
      (CONNECT_DATA = 
        (SID = testd)
           (GLOBAL_NAME = testd.testdb.com.ph)
      )
  )
testp.cfg = 
  (DESCRIPTION = 
        (ADDRESS = 
          (COMMUNITY = tcpip.world)
          (PROTOCOL = TCP)
          (Host = testp1)
          (Port = 5000)
        )
      (CONNECT_DATA = 
        (SID = testp)
           (GLOBAL_NAME = testp.cfg)
      )
  )

From what I understand, the nawk excludes all lines that begins with a # and if it finds a line that begins with testp.cfg or testp.cfg.testdb.com.ph, and starting from that line, it reads a line, strips the spaces, and convert it to lower case. Now I don't understand what this section of the nawk does?


Code:
     if (s~/host=/) {
        sub("^.*host=","",s)
        sub("\\\).*","",s)
        print s
        exit
     }
     c++
     if (c>20) {exit}


Does the first sub strips all spaces before the host= string? But what does the second sub do? Remove everything from the first dot (.)?

Is the c variable means it will only process 20 lines from when it find the testp.cfg or testp.cfg.testdb.com.ph string?

Any feedback much appreciated. Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. AIX

NIM Guidance

I've just started to explore NIM and I'm looking for additional information on how to set it up and configure it. I've read through the "NIM A-Z" and have many unanswered questions. One question is how can I have the NIM server pull a mksysb of the clients and can I schedule this to happen... (1 Reply)
Discussion started by: scottsl
1 Replies

2. What is on Your Mind?

Career Guidance

Hi, I am a newbie to Unix, I was introduced to UNIX 8 months back during my Training, I was attracted to Unix as they give complete freedom. I would like to ask how can a OS Admin can go into development field of Unix. Currently I am working in a MNC in Backup- Storage Admin Domain I am... (1 Reply)
Discussion started by: sufi_431
1 Replies

3. Shell Programming and Scripting

A little guidance needed :)

Hi guys, I'm learning the ropes of BASH and am doing a few exercises to see if its sinking in but have gotten stuck on something I KNOW is looking at me right in the face but just isn't registering. I'm creating a script that needs to get specific strings from a line. So using the "ls -l... (9 Replies)
Discussion started by: shadow0001
9 Replies

4. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

5. AIX

Need guidance on VMStat

I need some guidance on the differences in observations, not sure how significantly different are they. Also, It would be nice to hear on the values and what the obvious tuning for performance missing. Observation 1 ending vmstat -v 3948544 memory pages ending vmstat -v ... (1 Reply)
Discussion started by: Snipper
1 Replies

6. Shell Programming and Scripting

Need Some guidance on scripting

Hey All, I am newbie on scripting and need some guidance from all the experts here. I am working on one project where I will check the status/health of around ten (10) solaris 10 servers. I have one central server from where I have already setup the passwordless SFTP and setup the cron... (1 Reply)
Discussion started by: supercops
1 Replies

7. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

8. AIX

New to AIX. Need Guidance

Hi There, I am new to AIX. I am eager to learn the AIX System administration or if there is any other prerequisite before this. Please can anyone help me or guide how to start with AIX, what all courses and certifications do I need to do. I have basic knowledge of UNIX. Please guide as I am... (3 Replies)
Discussion started by: rahulat302
3 Replies

9. UNIX for Beginners Questions & Answers

Looking for guidance on learning the shell

Hello everyone! I am a mechanical engineering student from Brazil, and I'm trying to get into numerical simulation in fluid dynamics. A teacher recommended OpenFoam and from what I've been reading, it seems that I need to get familiar with ''the Shell'' at first, and this is why I'm here. I... (2 Replies)
Discussion started by: Heisenflower
2 Replies

10. Shell Programming and Scripting

Guidance required in .profile

Not every server I use has bash so I wanted to add an option to check if bash exists. This is what I tried. This is the error message it gives "-bash: '". It works before I add the and option. if ; then echo hi source ~/.bashrc; fi (6 Replies)
Discussion started by: cokedude
6 Replies
ucblinks(1B)                                         SunOS/BSD Compatibility Package Commands                                         ucblinks(1B)

NAME
ucblinks - adds /dev entries to give SunOS 4.x compatible names to SunOS 5.x devices SYNOPSIS
/usr/ucb/ucblinks [-e rulebase] [-r rootdir] DESCRIPTION
ucblinks creates symbolic links under the /dev directory for devices whose SunOS 5.x names differ from their SunOS 4.x names. Where possi- ble, these symbolic links point to the device's SunOS 5.x name rather than to the actual /devices entry. ucblinks does not remove unneeded compatibility links; these must be removed by hand. ucblinks should be called each time the system is reconfiguration-booted, after any new SunOS 5.x links that are needed have been created, since the reconfiguration may have resulted in more compatibility names being needed. In releases prior to SunOS 5.4, ucblinks used a nawk rule-base to construct the SunOS 4.x compatible names. ucblinks no longer uses nawk for the default operation, although nawk rule-bases can still be specifed with the -e option. The nawk rule-base equivalent to the SunOS 5.4 default operation can be found in /usr/ucblib/ucblinks.awk. OPTIONS
-e rulebase Specify rulebase as the file containing nawk(1) pattern-action statements. -r rootdir Specify rootdir as the directory under which dev and devices will be found, rather than the standard root directory /. FILES
/usr/ucblib/ucblinks.awk sample rule-base for compatibility links ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
devlinks(1M), disks(1M), ports(1M), tapes(1M), attributes(5) SunOS 5.10 13 Apr 1994 ucblinks(1B)
All times are GMT -4. The time now is 04:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy