Sponsored Content
Full Discussion: Scripting on AIX with awk
Top Forums Shell Programming and Scripting Scripting on AIX with awk Post 302392690 by tmf33uk on Friday 5th of February 2010 06:42:55 AM
Old 02-05-2010
Scripting on AIX with awk

Hi,
I am very new to scripting, but I am very keen to learn.

Right now, I have an input file containing the output of ps -emo THREAD (in AIX) where the lines look something like this:
Code:
 
    USER    PID   PPID      TID ST  CP PRI SC    WCHAN        F     TT BND COMMAND
    root      1      0        - A    0  60  1        -   200003      -   - /etc/init
       -      -      -     4099 S    0  60  1        -   410410      -   - -
    root  61688      1        - A    0  60  1  117cf08   240001      -   - /usr/ccs/bin/shlap64
       -      -      -    86067 S    0  60  1  117cf08      400      -   - -
    root  69754      1        - A    0  60 14        *   240001      -   - /usr/sbin/syncd 60
       -      -      -    90307 S    0  60  1 f10001001b3e4730   410410      -   - -
       -      -      -   114837 S    0  60  1 f100010018bc4930   410410      -   - -
       -      -      -   147591 S    0  60  1 f10001001cd94cb0   410410      -   - -
       -      -      -   151687 S    0  60  1 f10001001b54c330   410410      -   - -
       -      -      -   155891 S    0  60  1        -  2400400      -   - -

I am trying to format this to an output file so that all threads (TID) have the process id they belong to in the 2nd field.

My idea is:
1) If $2 is not '-', then
a)send the whole line to the output file and
b)store the value of $2 in a variable $mt that can be used when the next line is read
2) Read the next line
a)if $2 is not '-', then send the whole line to the output file and
b)if $2 is '-', then replace this with the value of $mt taken from the previous line and write to the output file
c)in case of b) reconfirm the same value for $mt, as there may be more threads to the same pid to read.

This is what I have done:
Code:
#!/usr/bin/ksh
ifile="logs/all_THREAD_procs"
ofile="all_THREAD_procs_f"
while read line
do
        awk '{ if ( $2 != "-" ) {
                print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
                else    print $2 }
        }'
done < $ifile > ofile

If I comment out the else line, then it prints all the lines where $2 is not - to the output file, but when I run it with the else condition I get:
Code:
Syntax Error The source line is 3.
 The error context is
                         >>>    else <<<        print $2 }

I can´t find any examples of what I am trying to do, although I imagine it´s a simple mistake to spot for those of you that use awk regularly..

Thanks in advance!

Teresa.

Last edited by pludi; 02-05-2010 at 07:43 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

scripting guru's pls help me with scripting on AIX

can someone pls help me with the script for a files coming from one system to a particular directory and i want to write a script to move those files to another directory on different system by renaming the files... pls someone help me on this... thanking in anticipation.... (1 Reply)
Discussion started by: thatiprashant
1 Replies

2. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

3. AIX

scripting routing changes on aix 4.3 and 5x

Hi All, I need to script a routing changes on my aix servers. I can't use smitty, very slow. I need to delete the static routing and add a new one. I also need to change default routing. I know using route add and route delete but I think I remember that this is not enough that's why I... (2 Replies)
Discussion started by: itik
2 Replies

4. Shell Programming and Scripting

Scripting on AIX and using nohup

ok... want to start off by saying i am sorry for the ignorance... still trying to figure out the diffs between solaris and aix... and i think that is where i am running into problems... :o SITTIATION: we are doing an implementation for Oracle's CC&B... we recently switched from... (1 Reply)
Discussion started by: Dagaswolf
1 Replies

5. AIX

Scripting AIX date output !!

Hi, I am writing a korn shell script in AIX. I want to pass the date as a parameter to script and inside it should convert the format to +%a" "%h" "%d" "%Y. For e.g., a parameter passed as "20100301" should be converted to "Mon Mar 01 2010". I can easily do this with AIX "date" option for... (2 Replies)
Discussion started by: shibajighosh
2 Replies

6. Shell Programming and Scripting

Help with ksh scripting in AIX

I am looking for a script which does the following Script will run daily. 1.It will get snapshot off all filesystems including nfs mounts, automounts and clearcase mounts. 2.Then it will compare new snapshot with the snapshot created in the previous run. 3.If filesystem exists in... (20 Replies)
Discussion started by: saidiya
20 Replies

7. Shell Programming and Scripting

Need help in writing AIX ksh scripting

I need to write the script for the below constraints. Need your help urgently The PATH environment variable must conform to the following: • World-writeable directories (/tmp, /var/tmp etc) must not be placed in the PATH variable. • System directories must always be placed before local... (1 Reply)
Discussion started by: kmvinay
1 Replies

8. Shell Programming and Scripting

help in ksh scripting in aix

Hello gurus I am looking for a script : We need to generate a file list created by user id on a AIX box. Criteria 1: other than userid : dwimpid & aiadmin Criteria 2: Files older than 2 months ( it can be any user id ). File Path to Look: /project and /project1 Thx silu (7 Replies)
Discussion started by: silu
7 Replies

9. Shell Programming and Scripting

AIX 5.3 ksh Scripting

Hi, I posted a request for sever OS types earlier, but got no response. In an attempt to at least have a starting point, I think scaling it to one OS is preferred. Once I see the gist of it I can modify to account for different cases. I need a script that will go and check to see if an LDAP... (2 Replies)
Discussion started by: tekster2
2 Replies

10. Shell Programming and Scripting

Need help in scripting in AIX

Hello, In a loop I am using below command for every database crsctl status res | grep -E "ora\.$DATABASE\.(.+)\.svc" and below is one of the sample output NAME=ora.sgraphut.sgraphutxdb.svc Now I want to extract just service name out of this string (that is sgraphutxdb) please help me how... (1 Reply)
Discussion started by: Vishal_dba
1 Replies
CPP(1)							      General Commands Manual							    CPP(1)

NAME
cpp - C language preprocessor SYNOPSIS
cpp [ option ... ] [ ifile [ ofile ] ] DESCRIPTION
Cpp interprets ANSI C preprocessor directives and does macro substitution. The input ifile and output ofile default to standard input and standard output respectively. The options are: -Dname -Dname=def -Idir Same as in 2c(1). -M Generate no output except a list of include files in a form suitable for specifying dependencies to mk(1). Use twice to list files in angle brackets. -N Turn off default include directories. All must be specified with -I. Without this option, /$objtype/include and /sys/include are used as the last two searched directories for include directives, where $objtype is read from the environment. -V Print extra debugging information. -+ Understand C++ comments. The output file contains processed text sprinkled with lines that show the original input line numbering: #line linenumber "ifile" The input language is as described in the ANSI C standard. The C compilers do not use cpp; they contain their own simple but adequate pre- processor, so cpp is usually superfluous. FILES
/sys/include directory for machine-independent include files /$objtype/include directory for machine-dependent include files SOURCE
/sys/src/cmd/cpp SEE ALSO
2c(1) CPP(1)
All times are GMT -4. The time now is 10:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy