Change format and align the count

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-2
down vote

favorite












I want to change the format



From:
Sample.txt



 Count Data
1 C0263/Pre-approved Auto Load BC
1 C0263/Pre-approved Auto Load BC Holders
3 C0268/Pre-approved Auto Loan


To:
Output.txt



 Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto BC Holders 1
C0268/Pre-approved Auto Loan 3






share|improve this question






















  • So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
    – AlexP
    Nov 6 '17 at 11:18










  • Isn’t that what Questions are for, @AlexP?
    – Jeff Schaller
    Nov 6 '17 at 11:32










  • are there a whitespaces at the begining of each line?
    – RomanPerekhrest
    Nov 6 '17 at 11:36











  • @JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
    – AlexP
    Nov 6 '17 at 11:38










  • Yes sir @RomanPerekhrest
    – John Christian Dela Cruz
    Nov 6 '17 at 11:42














up vote
-2
down vote

favorite












I want to change the format



From:
Sample.txt



 Count Data
1 C0263/Pre-approved Auto Load BC
1 C0263/Pre-approved Auto Load BC Holders
3 C0268/Pre-approved Auto Loan


To:
Output.txt



 Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto BC Holders 1
C0268/Pre-approved Auto Loan 3






share|improve this question






















  • So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
    – AlexP
    Nov 6 '17 at 11:18










  • Isn’t that what Questions are for, @AlexP?
    – Jeff Schaller
    Nov 6 '17 at 11:32










  • are there a whitespaces at the begining of each line?
    – RomanPerekhrest
    Nov 6 '17 at 11:36











  • @JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
    – AlexP
    Nov 6 '17 at 11:38










  • Yes sir @RomanPerekhrest
    – John Christian Dela Cruz
    Nov 6 '17 at 11:42












up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I want to change the format



From:
Sample.txt



 Count Data
1 C0263/Pre-approved Auto Load BC
1 C0263/Pre-approved Auto Load BC Holders
3 C0268/Pre-approved Auto Loan


To:
Output.txt



 Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto BC Holders 1
C0268/Pre-approved Auto Loan 3






share|improve this question














I want to change the format



From:
Sample.txt



 Count Data
1 C0263/Pre-approved Auto Load BC
1 C0263/Pre-approved Auto Load BC Holders
3 C0268/Pre-approved Auto Loan


To:
Output.txt



 Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto BC Holders 1
C0268/Pre-approved Auto Loan 3








share|improve this question













share|improve this question




share|improve this question








edited Nov 6 '17 at 11:43

























asked Nov 6 '17 at 10:41









John Christian Dela Cruz

215




215











  • So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
    – AlexP
    Nov 6 '17 at 11:18










  • Isn’t that what Questions are for, @AlexP?
    – Jeff Schaller
    Nov 6 '17 at 11:32










  • are there a whitespaces at the begining of each line?
    – RomanPerekhrest
    Nov 6 '17 at 11:36











  • @JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
    – AlexP
    Nov 6 '17 at 11:38










  • Yes sir @RomanPerekhrest
    – John Christian Dela Cruz
    Nov 6 '17 at 11:42
















  • So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
    – AlexP
    Nov 6 '17 at 11:18










  • Isn’t that what Questions are for, @AlexP?
    – Jeff Schaller
    Nov 6 '17 at 11:32










  • are there a whitespaces at the begining of each line?
    – RomanPerekhrest
    Nov 6 '17 at 11:36











  • @JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
    – AlexP
    Nov 6 '17 at 11:38










  • Yes sir @RomanPerekhrest
    – John Christian Dela Cruz
    Nov 6 '17 at 11:42















So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
– AlexP
Nov 6 '17 at 11:18




So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
– AlexP
Nov 6 '17 at 11:18












Isn’t that what Questions are for, @AlexP?
– Jeff Schaller
Nov 6 '17 at 11:32




Isn’t that what Questions are for, @AlexP?
– Jeff Schaller
Nov 6 '17 at 11:32












are there a whitespaces at the begining of each line?
– RomanPerekhrest
Nov 6 '17 at 11:36





are there a whitespaces at the begining of each line?
– RomanPerekhrest
Nov 6 '17 at 11:36













@JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
– AlexP
Nov 6 '17 at 11:38




@JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
– AlexP
Nov 6 '17 at 11:38












Yes sir @RomanPerekhrest
– John Christian Dela Cruz
Nov 6 '17 at 11:42




Yes sir @RomanPerekhrest
– John Christian Dela Cruz
Nov 6 '17 at 11:42










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










awk solution:



awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next 
f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt


The output:



 Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto Load BC Holders 1
C0268/Pre-approved Auto Loan 3





share|improve this answer




















  • It doesn’t work sir
    – John Christian Dela Cruz
    Nov 6 '17 at 13:41










  • @JohnChristianDelaCruz, why did not you post the output of awk --version (as was asked) ?
    – RomanPerekhrest
    Nov 6 '17 at 14:04











  • When applying the script you gave, the output is C0263/Pre-approved only
    – John Christian Dela Cruz
    Nov 6 '17 at 14:38










  • @JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
    – RomanPerekhrest
    Nov 6 '17 at 14:55











  • it works! Thanks a lot sir!
    – John Christian Dela Cruz
    Nov 7 '17 at 1:47

















up vote
0
down vote













Assuming the input data is in the file datafile.txt and you are using a POSIX shell, you can say



sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
printf '%-30.29s%sn' "$b" "$a"
done


The sed command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while loop which reads two fields separated by a colon then prints them nicely.



If the input data comes from a pipe then delete the datafile.txt argument and pipe it into sed.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f402805%2fchange-format-and-align-the-count%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    awk solution:



    awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next 
    f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt


    The output:



     Data Count
    C0263/Pre-approved Auto Load BC 1
    C0263/Pre-approved Auto Load BC Holders 1
    C0268/Pre-approved Auto Loan 3





    share|improve this answer




















    • It doesn’t work sir
      – John Christian Dela Cruz
      Nov 6 '17 at 13:41










    • @JohnChristianDelaCruz, why did not you post the output of awk --version (as was asked) ?
      – RomanPerekhrest
      Nov 6 '17 at 14:04











    • When applying the script you gave, the output is C0263/Pre-approved only
      – John Christian Dela Cruz
      Nov 6 '17 at 14:38










    • @JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
      – RomanPerekhrest
      Nov 6 '17 at 14:55











    • it works! Thanks a lot sir!
      – John Christian Dela Cruz
      Nov 7 '17 at 1:47














    up vote
    1
    down vote



    accepted










    awk solution:



    awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next 
    f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt


    The output:



     Data Count
    C0263/Pre-approved Auto Load BC 1
    C0263/Pre-approved Auto Load BC Holders 1
    C0268/Pre-approved Auto Loan 3





    share|improve this answer




















    • It doesn’t work sir
      – John Christian Dela Cruz
      Nov 6 '17 at 13:41










    • @JohnChristianDelaCruz, why did not you post the output of awk --version (as was asked) ?
      – RomanPerekhrest
      Nov 6 '17 at 14:04











    • When applying the script you gave, the output is C0263/Pre-approved only
      – John Christian Dela Cruz
      Nov 6 '17 at 14:38










    • @JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
      – RomanPerekhrest
      Nov 6 '17 at 14:55











    • it works! Thanks a lot sir!
      – John Christian Dela Cruz
      Nov 7 '17 at 1:47












    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    awk solution:



    awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next 
    f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt


    The output:



     Data Count
    C0263/Pre-approved Auto Load BC 1
    C0263/Pre-approved Auto Load BC Holders 1
    C0268/Pre-approved Auto Loan 3





    share|improve this answer












    awk solution:



    awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next 
    f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt


    The output:



     Data Count
    C0263/Pre-approved Auto Load BC 1
    C0263/Pre-approved Auto Load BC Holders 1
    C0268/Pre-approved Auto Loan 3






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 6 '17 at 11:56









    RomanPerekhrest

    22.5k12145




    22.5k12145











    • It doesn’t work sir
      – John Christian Dela Cruz
      Nov 6 '17 at 13:41










    • @JohnChristianDelaCruz, why did not you post the output of awk --version (as was asked) ?
      – RomanPerekhrest
      Nov 6 '17 at 14:04











    • When applying the script you gave, the output is C0263/Pre-approved only
      – John Christian Dela Cruz
      Nov 6 '17 at 14:38










    • @JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
      – RomanPerekhrest
      Nov 6 '17 at 14:55











    • it works! Thanks a lot sir!
      – John Christian Dela Cruz
      Nov 7 '17 at 1:47
















    • It doesn’t work sir
      – John Christian Dela Cruz
      Nov 6 '17 at 13:41










    • @JohnChristianDelaCruz, why did not you post the output of awk --version (as was asked) ?
      – RomanPerekhrest
      Nov 6 '17 at 14:04











    • When applying the script you gave, the output is C0263/Pre-approved only
      – John Christian Dela Cruz
      Nov 6 '17 at 14:38










    • @JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
      – RomanPerekhrest
      Nov 6 '17 at 14:55











    • it works! Thanks a lot sir!
      – John Christian Dela Cruz
      Nov 7 '17 at 1:47















    It doesn’t work sir
    – John Christian Dela Cruz
    Nov 6 '17 at 13:41




    It doesn’t work sir
    – John Christian Dela Cruz
    Nov 6 '17 at 13:41












    @JohnChristianDelaCruz, why did not you post the output of awk --version (as was asked) ?
    – RomanPerekhrest
    Nov 6 '17 at 14:04





    @JohnChristianDelaCruz, why did not you post the output of awk --version (as was asked) ?
    – RomanPerekhrest
    Nov 6 '17 at 14:04













    When applying the script you gave, the output is C0263/Pre-approved only
    – John Christian Dela Cruz
    Nov 6 '17 at 14:38




    When applying the script you gave, the output is C0263/Pre-approved only
    – John Christian Dela Cruz
    Nov 6 '17 at 14:38












    @JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
    – RomanPerekhrest
    Nov 6 '17 at 14:55





    @JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
    – RomanPerekhrest
    Nov 6 '17 at 14:55













    it works! Thanks a lot sir!
    – John Christian Dela Cruz
    Nov 7 '17 at 1:47




    it works! Thanks a lot sir!
    – John Christian Dela Cruz
    Nov 7 '17 at 1:47












    up vote
    0
    down vote













    Assuming the input data is in the file datafile.txt and you are using a POSIX shell, you can say



    sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
    printf '%-30.29s%sn' "$b" "$a"
    done


    The sed command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while loop which reads two fields separated by a colon then prints them nicely.



    If the input data comes from a pipe then delete the datafile.txt argument and pipe it into sed.






    share|improve this answer
























      up vote
      0
      down vote













      Assuming the input data is in the file datafile.txt and you are using a POSIX shell, you can say



      sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
      printf '%-30.29s%sn' "$b" "$a"
      done


      The sed command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while loop which reads two fields separated by a colon then prints them nicely.



      If the input data comes from a pipe then delete the datafile.txt argument and pipe it into sed.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Assuming the input data is in the file datafile.txt and you are using a POSIX shell, you can say



        sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
        printf '%-30.29s%sn' "$b" "$a"
        done


        The sed command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while loop which reads two fields separated by a colon then prints them nicely.



        If the input data comes from a pipe then delete the datafile.txt argument and pipe it into sed.






        share|improve this answer












        Assuming the input data is in the file datafile.txt and you are using a POSIX shell, you can say



        sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
        printf '%-30.29s%sn' "$b" "$a"
        done


        The sed command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while loop which reads two fields separated by a colon then prints them nicely.



        If the input data comes from a pipe then delete the datafile.txt argument and pipe it into sed.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 6 '17 at 11:49









        AlexP

        6,656924




        6,656924



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f402805%2fchange-format-and-align-the-count%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Christian Cage

            How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?