AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
Expand all | Collapse all

unix file line length wrapping script

  • 1.  unix file line length wrapping script

    Posted Fri April 27, 2018 04:50 AM

    Originally posted by: pktcs


    I have a requirement. Unix file have restriction of 80 line length if it is crossing 80 length of a line in Unix file then it has to check before that word any , (or)  space between words, from there it should go to next line. This command should run in AIX Unix. 

    Basically command has to check each line in a file whether it is crossing 80 length.

     

    Example : crossing 80 length so checked before word space is appeared, from there wrapped to next line.

    ,((Coalesce(T.RowSec21_IFDG_Suppress_Ind, P.RowSec21_IFDG_Suppress_Ind))  (char(1)))

     

    o/p :

    ,((Coalesce(T.RowSec21_IFDG_Suppress_Ind, P.RowSec21_IFDG_Suppress_Ind))
     (char(1)))

     

    Example: crossing 80 length so checked before word , is appeared, from there wrapped to next line

     

    ,((Coalesce(T.RowSec21_IFDG_Suppress_Ind, P.RowSec21_IFDG_Suppress_Ind)), (char(1)))

     

    o/p:

     

    ,((Coalesce(T.RowSec21_IFDG_Suppress_Ind, P.RowSec21_IFDG_Suppress_Ind))
     (char(1)))



  • 2.  Re: unix file line length wrapping script

    Posted Sat May 05, 2018 01:02 PM

    Originally posted by: Baskar Sundaram Ganesan


    Hi,

    Could you execute the below  mentioned command . It is working.. i tested with your sample input.

     

    awk '{if ( length($0) > 80 ) \
        { \
            if ( $0 ~/[\s,]\s/ ) \
            { \
            FS=" " ;\
            line2=$NF;\
            $NF="";\
                line1=$0;\
                print line1,"\n",line2;\
            } \
        } \
    }' yourinputfile



  • 3.  Re: unix file line length wrapping script

    Posted Mon May 07, 2018 12:27 AM

    Originally posted by: pktcs


    Thank you very much for prompt reply.

     

    I tried but the error is coming as below. Requesting you to please check them.

    I am attaching sample file to test them. 

     

     syntax error The source line is 1.
     The error context is
                    {if ( length($0) > 80 ) >>>  \ <<<
     awk: The statement cannot be correctly parsed.
     The source line is 1.
     syntax error The source line is 2.

     



  • 4.  Re: unix file line length wrapping script

    Posted Mon May 07, 2018 05:54 AM

    Originally posted by: pktcs


    Hi Baskar,

     

    Please share your mobile number. I need to have a quick call to discuss further. Thanks

    My number: 9003036683



  • 5.  Re: unix file line length wrapping script

    Posted Mon May 21, 2018 02:54 AM

    Originally posted by: pktcs


    Hi Basker,

     

    Thanks a lot for your answer.

     

    I have another requirement, could you please help in that matter.

     

    Basically the above script is giving output as whichever record length is crossing 80. Ideally output should contain both >80 and <80 records.

     

    Also, this has to apply onfly, is it possible?. Please help in this matter ASAP, it's urgent. I am desperately need your help.

     

    Example : crossing 80 length so checked before word space is appeared, from there wrapped to next line.

    ,((Coalesce(T.RowSec21_IFDG_Suppress_Ind, P.RowSec21_IFDG_Suppress_Ind))  (char(1)))
    ,((Coalesce(T.RowSec22_IFDG_Suppress, P.RowSec22_IFDG_Suppress))  (char(1)))
    ,((Coalesce(T.RowSec23_IFDG_Suppress, P.RowSec23_IFDG_Suppress))  (char(1)))

     

    o/p :

    ,((Coalesce(T.RowSec21_IFDG_Suppress_Ind, P.RowSec21_IFDG_Suppress_Ind))
      (char(1)))
    ,((Coalesce(T.RowSec22_IFDG_Suppress, P.RowSec22_IFDG_Suppress))  (char(1)))
    ,((Coalesce(T.RowSec23_IFDG_Suppress, P.RowSec23_IFDG_Suppress))  (char(1)))

     

    Thanks in advance.