Need next line as a space delimiter in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need next line as a space delimiter in awk
# 1  
Old 12-12-2013
Need next line as a space delimiter in awk

Hi,Below is the output for p3fi_dev services

Code:
1/app/oracle> . ./oraprofile_p3fi_dev
[dev-oragrid-ux01]p3fi_dev_01 (P):/devoragridcn_01/app/oracle> srvctl config service -d p3fi_dev
p3fi_p3fi_dev.world PREF: p3fi_dev_01 AVAIL: p3fi_dev_02
pplnet_p3fidev PREF: p3fi_dev_01 AVAIL: p3fi_dev_02
nexus_p3fidev PREF: p3fi_dev_01 AVAIL: p3fi_dev_02
applog_p3fidev PREF: p3fi_dev_01 AVAIL: p3fi_dev_02


I need distinct values fro PREF and AVAIL out of the above output

Below is the code I am using:

Code:
case $ORACLE_HOME in
  */product/10*)
# i# *)              echo "something else" ;;
#esac
Instance_value=`srvctl config service -d $database | awk -F: '
/PREF/ {
                P[$NF]
        }
        /AVAIL/ {
                A[$NF]
        }
        END {
                printf ( "%s:", "Preferred instances" )
                for ( k in P )
                        printf ( "%s ", k )

                printf ( "\n%s:", "Available instances" )
                for ( k in A )
                        printf ( "%s ", k )

                printf "\n"
        }
'`;;


However this is giving blank values for Preferred and Available instances.


Please suggest.


Best regards,
Vishal
# 2  
Old 12-12-2013
show expected output also for your input.
# 3  
Old 12-12-2013
Below is the expected output:

Code:
Checking services for database p3fi_dev
p3fi_p3fi_dev.world
pplnet_p3fidev
nexus_p3fidev
applog_p3fidev
Preferred instances: p3fi_dev_01 Available instances: p3fi_dev_02



Best regards,
Vishal
# 4  
Old 12-12-2013
I assumed this is input

Code:
$ cat file
p3fi_p3fi_dev.world PREF: p3fi_dev_01 AVAIL: p3fi_dev_02
pplnet_p3fidev PREF: p3fi_dev_01 AVAIL: p3fi_dev_02
nexus_p3fidev PREF: p3fi_dev_01 AVAIL: p3fi_dev_02
applog_p3fidev PREF: p3fi_dev_01 AVAIL: p3fi_dev_02

Code:
database=p3fi_dev
awk -v data=$database '
BEGIN{
        print "Checking services for database ", data
     }
     {
        P[$3]
        A[$5]
        print $1
     }
  END{
        printf ( "%s : ", "Preferred instances" )
        for(i in P)printf i
        printf("\t%s : ", "Available instances" )
        for(i in A)printf i
        printf RS
     }' file

Resulting
Code:
Checking services for database  p3fi_dev
p3fi_p3fi_dev.world
pplnet_p3fidev
nexus_p3fidev
applog_p3fidev
Preferred instances : p3fi_dev_01    Available instances : p3fi_dev_02

----edit-------

create variable like this
Code:
Instance_value=$(srvctl config service -d $database  | \
awk -v data=$database '
BEGIN{
        print "Checking services for database ", data
     }
     {
       P[$3]
       A[$5]
       print $1
     }
  END{
        printf ( "%s : ", "Preferred instances" )
        for(i in P)printf i
        printf("\t%s : ", "Available instances" )
        for(i in A)printf i
        printf RS
     }' )


printf  "$Instance_value\n"


Last edited by Akshay Hegde; 12-12-2013 at 02:19 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join the line on delimiter using sed/awk in UNIX

I've input as , abcd| ef 123456| 78| 90 Desired output as, abcdef 1234567890 Anyone please give the solution. (5 Replies)
Discussion started by: jinixvimal
5 Replies

2. Shell Programming and Scripting

Need to use delimiter as : and space in awk

Hi , Please suggest me how do I use : (colon and one space) as a delimiter in awk Best regards, Vishal (2 Replies)
Discussion started by: Vishal_dba
2 Replies

3. Shell Programming and Scripting

awk until blank space and print next line

Hello and Happy New Year 2012! I have this example: 1,2,3 4,5,6 7,8,9 For that, I'm trying to get: 1,2,3 4,5,6 7,8,9 for that, I think this might work but doesnt work so far: awk '{for(i=1;i=NF;i++);sub(/\//,"",$i);print $i}' myfile (2 Replies)
Discussion started by: Gery
2 Replies

4. Shell Programming and Scripting

Implement in one line sed or awk having no delimiter and file size is huge

I have file which contains around 5000 lines. The lines are fixed legth but having no delimiter.Each line line contains nearly 3000 characters. I want to delete the lines a> if it starts with 1 and if 576th postion is a digit i,e 0-9 or b> if it starts with 0 or 9(i,e header and footer) ... (4 Replies)
Discussion started by: millan
4 Replies

5. Shell Programming and Scripting

how to implement in one-line awk in a fixed file having no delimiter

Hi, I have a file a.txt having no delimiter. I want to exclude the line which contains 435th character as 1 or 2 and redirect the rest of the lines to another file b. Can you pls suggest how to do this in one liner awk. Following is just one line of the input file a:- 120110116 ... (10 Replies)
Discussion started by: millan
10 Replies

6. Shell Programming and Scripting

Space as a delimiter

not sure if i'm doing this right i'm new tho this but i'm trying to use a space as a delimiter with the cut command my code is size=$( du -k -S -s /home/cmik | cut -d' ' -f1 ) i've also tried -f2 and switching the -d and -f around if that does anything (3 Replies)
Discussion started by: Cmik
3 Replies

7. Shell Programming and Scripting

comma delimiter and space

I have a csv file and there is a problem which I need to resolve. Column1,Column2,Colum3,Column4 ,x,y,z ,d,c,v t,l,m,n ,h,s,k ,k,,y z,j, ,p Now if you see column1 for row 1 and row 4 though they are null there is a space but in case of row2 and row 5 there is no space. I want row... (3 Replies)
Discussion started by: RubinPat
3 Replies

8. UNIX for Dummies Questions & Answers

Delimiter: Tab or Space?

Hello, Is there a direct command to check if the delimiter in your file is a tab or a space? And how can they be converted from one to another. Thanks, G (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

9. UNIX for Dummies Questions & Answers

Problem Using Cut With A Space Delimiter

I am trying to extract 'postmaster' from the following string: PenaltyError:=554 5.7.1 Error, send your mail to postmaster@LOCALDOMAIN using the following command: cat /usr/share/assp/assp.cfg | grep ^PenaltyError:= | cut -d '@' -f1 | cut -f8 but it returns: PenaltyError:=554 5.7.1 Error,... (10 Replies)
Discussion started by: cleanden
10 Replies

10. UNIX for Dummies Questions & Answers

replacing space with pipe(delimiter)

Hello All, I have a file with thousands of records: eg: |000222|123456987|||||||AARONSON| JOHN P|||PRIMARY |P |000111|567894521|||||||ATHENS| WILLIAM k|||AAAA|L Expected: |000222|123456987|||||||AARONSON| JOHN |P|||PRIMARY |P |000111|567894521|||||||ATHENS| WILLIAM |k|||AAAA|L I... (6 Replies)
Discussion started by: OSD
6 Replies
Login or Register to Ask a Question