Sponsored Content
Top Forums Shell Programming and Scripting Need next line as a space delimiter in awk Post 302879443 by Akshay Hegde on Thursday 12th of December 2013 01:10:13 PM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
MYSQLI_SELECT_DB(3)							 1						       MYSQLI_SELECT_DB(3)

mysqli::select_db - Selects the default database for database queries

       Object oriented style

SYNOPSIS
bool mysqli::select_db (string $dbname) DESCRIPTION
Procedural style bool mysqli_select_db (mysqli $link, string $dbname) Selects the default database to be used when performing queries against the database connection. Note This function should only be used to change the default database for the connection. You can select the default database with 4th parameter in mysqli_connect(3). PARAMETERS
o $ link -Procedural style only: A link identifier returned by mysqli_connect(3) or mysqli_init(3) o $dbname - The database name. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 mysqli::select_db example Object oriented style <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "test"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } /* return name of current default database */ if ($result = $mysqli->query("SELECT DATABASE()")) { $row = $result->fetch_row(); printf("Default database is %s. ", $row[0]); $result->close(); } /* change db to world db */ $mysqli->select_db("world"); /* return name of current default database */ if ($result = $mysqli->query("SELECT DATABASE()")) { $row = $result->fetch_row(); printf("Default database is %s. ", $row[0]); $result->close(); } $mysqli->close(); ?> Procedural style <?php $link = mysqli_connect("localhost", "my_user", "my_password", "test"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", mysqli_connect_error()); exit(); } /* return name of current default database */ if ($result = mysqli_query($link, "SELECT DATABASE()")) { $row = mysqli_fetch_row($result); printf("Default database is %s. ", $row[0]); mysqli_free_result($result); } /* change db to world db */ mysqli_select_db($link, "world"); /* return name of current default database */ if ($result = mysqli_query($link, "SELECT DATABASE()")) { $row = mysqli_fetch_row($result); printf("Default database is %s. ", $row[0]); mysqli_free_result($result); } mysqli_close($link); ?> The above examples will output: Default database is test. Default database is world. SEE ALSO
mysqli_connect(3), mysqli_real_connect(3). PHP Documentation Group MYSQLI_SELECT_DB(3)
All times are GMT -4. The time now is 05:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy