Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2002
    Location
    Madrid - Spain
    Posts
    422
    Provided Answers: 1

    Unanswered: output correct in file.

    Hi colleagues,

    I have this file.
    tablas_tablespace_prueba
    select count(*) from schema.table1 with UR;
    select count(*) from schema.table2 with UR;
    select count(*) from schema.table3 with UR;
    select count(*) from schema.table4 with UR;
    select count(*) from schema.table5 with UR;
    select count(*) from schema.table5 with UR;

    I am executing this command
    db2 -tvxf tablas_tablespace_prueba | sed '$!N;s/\n//'

    The output is.
    select count(*) from ATLPU02.A0RANGTD with UR 38819
    select count(*) from ATLPU02.A0ARMZTD with UR
    72072
    select count(*) from ATLPU02.A0BASTTD with UR 43332
    select count(*) from ATLPU02.A0CAPETD with UR
    5571
    select count(*) from ATLPU02.A0CVLOTD with UR 58413
    select count(*) from ATLPU02.A0FHILTD with UR
    1834
    select count(*) from ATLPU02.A0GNIBTD with UR 5020
    select count(*) from ATLPU02.A0REGLTD with UR
    231680
    select count(*) from ATLPU02.A0RANUTD with UR 349997
    select count(*) from ATLPU02.A0RGASTD with UR
    131186
    select count(*) from ATLPU02.A0DIPHTD with UR 487
    select count(*) from ATLPU02.A0PCCSTD with UR
    72287
    select count(*) from ATLPU02.A0PCTATD with UR 50500
    select count(*) from ATLPU02.A0TNRPTD with UR
    1257

    for me the output correct is this.
    select count(*) from ATLPU02.A0RANGTD with UR 38819
    select count(*) from ATLPU02.A0ARMZTD with UR 72072
    select count(*) from ATLPU02.A0BASTTD with UR 43332
    select count(*) from ATLPU02.A0CAPETD with UR 5571
    select count(*) from ATLPU02.A0CVLOTD with UR 58413
    select count(*) from ATLPU02.A0FHILTD with UR 1834
    select count(*) from ATLPU02.A0GNIBTD with UR 5020
    select count(*) from ATLPU02.A0REGLTD with UR 231680
    select count(*) from ATLPU02.A0RANUTD with UR 349997
    select count(*) from ATLPU02.A0RGASTD with UR 131186
    select count(*) from ATLPU02.A0DIPHTD with UR 487
    select count(*) from ATLPU02.A0PCCSTD with UR 72287
    select count(*) from ATLPU02.A0PCTATD with UR 50500
    select count(*) from ATLPU02.A0TNRPTD with UR 1257

    Somebody can help me, please.

    Thank you for advanced.
    DBA DB2 for LUW

  2. #2
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    Your question is not about DB2 then, it is about 'sed'.
    There are many different ways to do it, either with sed or awk or even in sql.
    But one way is to make a small file with a sed script in it, and then use
    Code:
    db2 -txvf  yourfile | sed -f sedscript
    if your sedscript looks like this:

    Code:
    /^select/{
    N
    s/\n//
    }
    As I say, there are many ways to do it...

  3. #3
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    i remember a discussion on this one a few weeks back .. Was it your post OP?

    Your problem is because the sed joins a pair of lines, joins 1,2 ; 3,4 ; 5,6 ; 7,8 but every thrid line of your original output [ ie without sed ] is blank, ie lines 3, 6 ,9 etc.

    To circumvent this, you have to remove blank lines before passing it to sed

    Code:
     db2 -tvxf tablas_tablespace_prueba | sed '/./!d' | sed '$!N;s/\n//'
    I am no sed expert. Someone with a good grasp of sed will be able to suggest a single sed command instead of my two.

    HTH
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  4. #4
    Join Date
    Dec 2002
    Location
    Madrid - Spain
    Posts
    422
    Provided Answers: 1
    Thank you for the answers,

    could someone tell me what the correct command to obtain the desired output.

    Thank you for advanced.
    DBA DB2 for LUW

  5. #5
    Join Date
    Oct 2009
    Location
    221B Baker St.
    Posts
    486
    Did you try the code provided? If not, why not?

    If you tried it and it did not do what you want, you need to post the code you ran (use copy/paste - do not re-type) and explain what it did do.

  6. #6
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    Try this:
    Code:
    db2 -tvxf tablas_tablespace_prueba | perl -p0e 's/\s+(\d+)\s+/\t$1\n/g'
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting
    __http://www.abis.be/

  7. #7
    Join Date
    Dec 2002
    Location
    Madrid - Spain
    Posts
    422
    Provided Answers: 1
    thank you very much for all your responses colleagues

    Greetings.
    DBA DB2 for LUW

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •