How to reformat text in a file to another direction?

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











up vote
7
down vote

favorite












I have table in the current format:



Lead:Arrow1:Arrow2:Arrow3
Follow:Arrow4:Arrow5:Arrow6:Arrow7:Arrow8:Arrow9


I want to turn this to the



Lead
Arrow1
Arrow2
Arrow3
Follow
Arrow4
Arrow5
Arrow6
Arrow7
Arrow8
Arrow9


I tried awk:



$(awk -F":" '/Lead/ print NF-1' $f)
$(awk -F":" '/Follow/ print NF-1' $f)


but it didn't work. How can I do it in awk or any other method?










share|improve this question









New contributor




kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 3




    Possible duplicate of Print each field of CSV on newline without knowing number of fields
    – Î±Ò“sнιη
    8 hours ago














up vote
7
down vote

favorite












I have table in the current format:



Lead:Arrow1:Arrow2:Arrow3
Follow:Arrow4:Arrow5:Arrow6:Arrow7:Arrow8:Arrow9


I want to turn this to the



Lead
Arrow1
Arrow2
Arrow3
Follow
Arrow4
Arrow5
Arrow6
Arrow7
Arrow8
Arrow9


I tried awk:



$(awk -F":" '/Lead/ print NF-1' $f)
$(awk -F":" '/Follow/ print NF-1' $f)


but it didn't work. How can I do it in awk or any other method?










share|improve this question









New contributor




kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 3




    Possible duplicate of Print each field of CSV on newline without knowing number of fields
    – Î±Ò“sнιη
    8 hours ago












up vote
7
down vote

favorite









up vote
7
down vote

favorite











I have table in the current format:



Lead:Arrow1:Arrow2:Arrow3
Follow:Arrow4:Arrow5:Arrow6:Arrow7:Arrow8:Arrow9


I want to turn this to the



Lead
Arrow1
Arrow2
Arrow3
Follow
Arrow4
Arrow5
Arrow6
Arrow7
Arrow8
Arrow9


I tried awk:



$(awk -F":" '/Lead/ print NF-1' $f)
$(awk -F":" '/Follow/ print NF-1' $f)


but it didn't work. How can I do it in awk or any other method?










share|improve this question









New contributor




kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have table in the current format:



Lead:Arrow1:Arrow2:Arrow3
Follow:Arrow4:Arrow5:Arrow6:Arrow7:Arrow8:Arrow9


I want to turn this to the



Lead
Arrow1
Arrow2
Arrow3
Follow
Arrow4
Arrow5
Arrow6
Arrow7
Arrow8
Arrow9


I tried awk:



$(awk -F":" '/Lead/ print NF-1' $f)
$(awk -F":" '/Follow/ print NF-1' $f)


but it didn't work. How can I do it in awk or any other method?







awk text-formatting






share|improve this question









New contributor




kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 17 mins ago









peterh

4,04792755




4,04792755






New contributor




kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 9 hours ago









kashef

383




383




New contributor




kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






kashef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 3




    Possible duplicate of Print each field of CSV on newline without knowing number of fields
    – Î±Ò“sнιη
    8 hours ago












  • 3




    Possible duplicate of Print each field of CSV on newline without knowing number of fields
    – Î±Ò“sнιη
    8 hours ago







3




3




Possible duplicate of Print each field of CSV on newline without knowing number of fields
– Î±Ò“sнιη
8 hours ago




Possible duplicate of Print each field of CSV on newline without knowing number of fields
– Î±Ò“sнιη
8 hours ago










2 Answers
2






active

oldest

votes

















up vote
12
down vote



accepted










You can use tr as follows:



<file tr ":" "n"

Lead
Arrow1
Arrow2
Arrow3
Follow
Arrow4
Arrow5
Arrow6
Arrow7
Arrow8
Arrow9


or awk as follows:



<file awk 'gsub(/:/,"n")1'
Lead
Arrow1
Arrow2
Arrow3
Follow
Arrow4
Arrow5
Arrow6
Arrow7
Arrow8
Arrow9





share|improve this answer


















  • 2




    Nice, with GNU awk you could also write awk -v RS='[:n]' 1
    – user000001
    7 hours ago

















up vote
0
down vote













Another super-simple solution would be to convert the :s to spaces with sed, and then print the words with echo in a for loop:



for i in $(sed 's/:/ /g')
do
echo $i
done


This script works from stdin to stdout.






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
    );



    );






    kashef is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474240%2fhow-to-reformat-text-in-a-file-to-another-direction%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
    12
    down vote



    accepted










    You can use tr as follows:



    <file tr ":" "n"

    Lead
    Arrow1
    Arrow2
    Arrow3
    Follow
    Arrow4
    Arrow5
    Arrow6
    Arrow7
    Arrow8
    Arrow9


    or awk as follows:



    <file awk 'gsub(/:/,"n")1'
    Lead
    Arrow1
    Arrow2
    Arrow3
    Follow
    Arrow4
    Arrow5
    Arrow6
    Arrow7
    Arrow8
    Arrow9





    share|improve this answer


















    • 2




      Nice, with GNU awk you could also write awk -v RS='[:n]' 1
      – user000001
      7 hours ago














    up vote
    12
    down vote



    accepted










    You can use tr as follows:



    <file tr ":" "n"

    Lead
    Arrow1
    Arrow2
    Arrow3
    Follow
    Arrow4
    Arrow5
    Arrow6
    Arrow7
    Arrow8
    Arrow9


    or awk as follows:



    <file awk 'gsub(/:/,"n")1'
    Lead
    Arrow1
    Arrow2
    Arrow3
    Follow
    Arrow4
    Arrow5
    Arrow6
    Arrow7
    Arrow8
    Arrow9





    share|improve this answer


















    • 2




      Nice, with GNU awk you could also write awk -v RS='[:n]' 1
      – user000001
      7 hours ago












    up vote
    12
    down vote



    accepted







    up vote
    12
    down vote



    accepted






    You can use tr as follows:



    <file tr ":" "n"

    Lead
    Arrow1
    Arrow2
    Arrow3
    Follow
    Arrow4
    Arrow5
    Arrow6
    Arrow7
    Arrow8
    Arrow9


    or awk as follows:



    <file awk 'gsub(/:/,"n")1'
    Lead
    Arrow1
    Arrow2
    Arrow3
    Follow
    Arrow4
    Arrow5
    Arrow6
    Arrow7
    Arrow8
    Arrow9





    share|improve this answer














    You can use tr as follows:



    <file tr ":" "n"

    Lead
    Arrow1
    Arrow2
    Arrow3
    Follow
    Arrow4
    Arrow5
    Arrow6
    Arrow7
    Arrow8
    Arrow9


    or awk as follows:



    <file awk 'gsub(/:/,"n")1'
    Lead
    Arrow1
    Arrow2
    Arrow3
    Follow
    Arrow4
    Arrow5
    Arrow6
    Arrow7
    Arrow8
    Arrow9






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 8 hours ago

























    answered 9 hours ago









    Goro

    7,94153777




    7,94153777







    • 2




      Nice, with GNU awk you could also write awk -v RS='[:n]' 1
      – user000001
      7 hours ago












    • 2




      Nice, with GNU awk you could also write awk -v RS='[:n]' 1
      – user000001
      7 hours ago







    2




    2




    Nice, with GNU awk you could also write awk -v RS='[:n]' 1
    – user000001
    7 hours ago




    Nice, with GNU awk you could also write awk -v RS='[:n]' 1
    – user000001
    7 hours ago












    up vote
    0
    down vote













    Another super-simple solution would be to convert the :s to spaces with sed, and then print the words with echo in a for loop:



    for i in $(sed 's/:/ /g')
    do
    echo $i
    done


    This script works from stdin to stdout.






    share|improve this answer
























      up vote
      0
      down vote













      Another super-simple solution would be to convert the :s to spaces with sed, and then print the words with echo in a for loop:



      for i in $(sed 's/:/ /g')
      do
      echo $i
      done


      This script works from stdin to stdout.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Another super-simple solution would be to convert the :s to spaces with sed, and then print the words with echo in a for loop:



        for i in $(sed 's/:/ /g')
        do
        echo $i
        done


        This script works from stdin to stdout.






        share|improve this answer












        Another super-simple solution would be to convert the :s to spaces with sed, and then print the words with echo in a for loop:



        for i in $(sed 's/:/ /g')
        do
        echo $i
        done


        This script works from stdin to stdout.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 16 mins ago









        peterh

        4,04792755




        4,04792755




















            kashef is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            kashef is a new contributor. Be nice, and check out our Code of Conduct.












            kashef is a new contributor. Be nice, and check out our Code of Conduct.











            kashef is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474240%2fhow-to-reformat-text-in-a-file-to-another-direction%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke