How can I use AWK to break line content into multiple lines using a separator2019 Community Moderator ElectionHow can you combine all lines that end with a backslash character?How can I use awk to (sometimes) remove the first character of a column?How to use AWK record separator?Merge two csvfiles by column headerCompare two files with four columnsHow to use Awk to format numbers with a thousands separatorComparing two lines in BASH using awkGet average for all rows every 3 columnsFinding and extracting immediate charactersHow can I use awk to get value multiple times from one file to other file?

Why is "la Gestapo" feminine?

Is xar preinstalled on macOS?

What is the reasoning behind standardization (dividing by standard deviation)?

How to read string as hex number in bash?

"Marked down as someone wanting to sell shares." What does that mean?

Turning a hard to access nut?

Asserting that Atheism and Theism are both faith based positions

Should I be concerned about student access to a test bank?

Can "few" be used as a subject? If so, what is the rule?

10 year ban after applying for a UK student visa

Emojional cryptic crossword

Why didn’t Eve recognize the little cockroach as a living organism?

Why doesn't the chatan sign the ketubah?

Can other pieces capture a threatening piece and prevent a checkmate?

How old is Nick Fury?

Does the Shadow Magic sorcerer's Eyes of the Dark feature work on all Darkness spells or just his/her own?

Why are there no stars visible in cislunar space?

Recursively updating the MLE as new observations stream in

TDE Master Key Rotation

Should a narrator ever describe things based on a characters view instead of fact?

Determine voltage drop over 10G resistors with cheap multimeter

pipe commands inside find -exec?

Hot air balloons as primitive bombers

Why I don't get the wanted width of tcbox?



How can I use AWK to break line content into multiple lines using a separator



2019 Community Moderator ElectionHow can you combine all lines that end with a backslash character?How can I use awk to (sometimes) remove the first character of a column?How to use AWK record separator?Merge two csvfiles by column headerCompare two files with four columnsHow to use Awk to format numbers with a thousands separatorComparing two lines in BASH using awkGet average for all rows every 3 columnsFinding and extracting immediate charactersHow can I use awk to get value multiple times from one file to other file?










0















Given an input like this:



field1,field2,field3,field4


I would like to get an output like this



field1
field2
field3
field4


How can I do this with awk?










share|improve this question









New contributor




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















  • 2





    how "like that" is your actual data? Because if there are multiple lines of input, you'll have more trouble distinguishing records afterwards (if that's even a problem).

    – Jeff Schaller
    11 hours ago











  • Does any field contain embedded commas?

    – Kusalananda
    11 hours ago











  • No embedded commas. Source file will have multiple lines but i mean to obtain just one before applying this parse

    – Santi
    10 hours ago















0















Given an input like this:



field1,field2,field3,field4


I would like to get an output like this



field1
field2
field3
field4


How can I do this with awk?










share|improve this question









New contributor




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















  • 2





    how "like that" is your actual data? Because if there are multiple lines of input, you'll have more trouble distinguishing records afterwards (if that's even a problem).

    – Jeff Schaller
    11 hours ago











  • Does any field contain embedded commas?

    – Kusalananda
    11 hours ago











  • No embedded commas. Source file will have multiple lines but i mean to obtain just one before applying this parse

    – Santi
    10 hours ago













0












0








0








Given an input like this:



field1,field2,field3,field4


I would like to get an output like this



field1
field2
field3
field4


How can I do this with awk?










share|improve this question









New contributor




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












Given an input like this:



field1,field2,field3,field4


I would like to get an output like this



field1
field2
field3
field4


How can I do this with awk?







linux text-processing awk






share|improve this question









New contributor




Santi 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




Santi 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 11 hours ago









Stephen Kitt

176k24401479




176k24401479






New contributor




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









asked 11 hours ago









SantiSanti

1011




1011




New contributor




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





New contributor





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






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







  • 2





    how "like that" is your actual data? Because if there are multiple lines of input, you'll have more trouble distinguishing records afterwards (if that's even a problem).

    – Jeff Schaller
    11 hours ago











  • Does any field contain embedded commas?

    – Kusalananda
    11 hours ago











  • No embedded commas. Source file will have multiple lines but i mean to obtain just one before applying this parse

    – Santi
    10 hours ago












  • 2





    how "like that" is your actual data? Because if there are multiple lines of input, you'll have more trouble distinguishing records afterwards (if that's even a problem).

    – Jeff Schaller
    11 hours ago











  • Does any field contain embedded commas?

    – Kusalananda
    11 hours ago











  • No embedded commas. Source file will have multiple lines but i mean to obtain just one before applying this parse

    – Santi
    10 hours ago







2




2





how "like that" is your actual data? Because if there are multiple lines of input, you'll have more trouble distinguishing records afterwards (if that's even a problem).

– Jeff Schaller
11 hours ago





how "like that" is your actual data? Because if there are multiple lines of input, you'll have more trouble distinguishing records afterwards (if that's even a problem).

– Jeff Schaller
11 hours ago













Does any field contain embedded commas?

– Kusalananda
11 hours ago





Does any field contain embedded commas?

– Kusalananda
11 hours ago













No embedded commas. Source file will have multiple lines but i mean to obtain just one before applying this parse

– Santi
10 hours ago





No embedded commas. Source file will have multiple lines but i mean to obtain just one before applying this parse

– Santi
10 hours ago










3 Answers
3






active

oldest

votes


















3














The idiomatic Awk way of doing this would probably be



awk 'BEGINFS=","; OFS="n" $1=$1 1'


or equivalently



awk '$1=$1 1' FS=, OFS='n'


The $1=$1 just forces re-evaluation of the record with the new separator OFS, and the 1 triggers the default print action. You can use other expressions, such as NF += 0, to force the re-evaluation if you prefer - it's a matter of preference.



A quick'n'dirty way would be



awk -vRS=, 1


(or awk 1 RS=,) which treats each comma-separated word as a whole record and outputs them with the default newline record separator.






share|improve this answer
































    2














    Use tr to translate the comma to a newline:



    echo "field1,field2,field3,field4" | tr "," "n"


    This is likely faster than using awk, though if you insist, you could do:



    echo "field1,field2,field3,field4" | awk 'gsub(",","n");print'


    From the GNU awk documentation:




    gsub(regexp, replacement [, target])



    Search target for all of the longest, leftmost, nonoverlapping matching substrings it can find and replace them with replacement. The ‘g’ in gsub() stands for “global,” which means replace everywhere.







    share|improve this answer

























    • Thanks, the tr solution is just what i needed

      – Santi
      10 hours ago


















    2














    Using bash and csvformat from the csvkit collection to change the field delimiter from a comma to a newline:



    $ csvformat -D $'n' file
    field1
    field2
    field3
    field4


    This is assuming that the input in file is properly formatted CSV. This would also properly handle embedded commas:



    $ cat file
    "field,1",field2,field3,field4
    $ csvformat -D $'n' file
    field,1
    field2
    field3
    field4





    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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );






      Santi 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%2f506987%2fhow-can-i-use-awk-to-break-line-content-into-multiple-lines-using-a-separator%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      The idiomatic Awk way of doing this would probably be



      awk 'BEGINFS=","; OFS="n" $1=$1 1'


      or equivalently



      awk '$1=$1 1' FS=, OFS='n'


      The $1=$1 just forces re-evaluation of the record with the new separator OFS, and the 1 triggers the default print action. You can use other expressions, such as NF += 0, to force the re-evaluation if you prefer - it's a matter of preference.



      A quick'n'dirty way would be



      awk -vRS=, 1


      (or awk 1 RS=,) which treats each comma-separated word as a whole record and outputs them with the default newline record separator.






      share|improve this answer





























        3














        The idiomatic Awk way of doing this would probably be



        awk 'BEGINFS=","; OFS="n" $1=$1 1'


        or equivalently



        awk '$1=$1 1' FS=, OFS='n'


        The $1=$1 just forces re-evaluation of the record with the new separator OFS, and the 1 triggers the default print action. You can use other expressions, such as NF += 0, to force the re-evaluation if you prefer - it's a matter of preference.



        A quick'n'dirty way would be



        awk -vRS=, 1


        (or awk 1 RS=,) which treats each comma-separated word as a whole record and outputs them with the default newline record separator.






        share|improve this answer



























          3












          3








          3







          The idiomatic Awk way of doing this would probably be



          awk 'BEGINFS=","; OFS="n" $1=$1 1'


          or equivalently



          awk '$1=$1 1' FS=, OFS='n'


          The $1=$1 just forces re-evaluation of the record with the new separator OFS, and the 1 triggers the default print action. You can use other expressions, such as NF += 0, to force the re-evaluation if you prefer - it's a matter of preference.



          A quick'n'dirty way would be



          awk -vRS=, 1


          (or awk 1 RS=,) which treats each comma-separated word as a whole record and outputs them with the default newline record separator.






          share|improve this answer















          The idiomatic Awk way of doing this would probably be



          awk 'BEGINFS=","; OFS="n" $1=$1 1'


          or equivalently



          awk '$1=$1 1' FS=, OFS='n'


          The $1=$1 just forces re-evaluation of the record with the new separator OFS, and the 1 triggers the default print action. You can use other expressions, such as NF += 0, to force the re-evaluation if you prefer - it's a matter of preference.



          A quick'n'dirty way would be



          awk -vRS=, 1


          (or awk 1 RS=,) which treats each comma-separated word as a whole record and outputs them with the default newline record separator.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 11 hours ago

























          answered 11 hours ago









          steeldriversteeldriver

          37.1k45287




          37.1k45287























              2














              Use tr to translate the comma to a newline:



              echo "field1,field2,field3,field4" | tr "," "n"


              This is likely faster than using awk, though if you insist, you could do:



              echo "field1,field2,field3,field4" | awk 'gsub(",","n");print'


              From the GNU awk documentation:




              gsub(regexp, replacement [, target])



              Search target for all of the longest, leftmost, nonoverlapping matching substrings it can find and replace them with replacement. The ‘g’ in gsub() stands for “global,” which means replace everywhere.







              share|improve this answer

























              • Thanks, the tr solution is just what i needed

                – Santi
                10 hours ago















              2














              Use tr to translate the comma to a newline:



              echo "field1,field2,field3,field4" | tr "," "n"


              This is likely faster than using awk, though if you insist, you could do:



              echo "field1,field2,field3,field4" | awk 'gsub(",","n");print'


              From the GNU awk documentation:




              gsub(regexp, replacement [, target])



              Search target for all of the longest, leftmost, nonoverlapping matching substrings it can find and replace them with replacement. The ‘g’ in gsub() stands for “global,” which means replace everywhere.







              share|improve this answer

























              • Thanks, the tr solution is just what i needed

                – Santi
                10 hours ago













              2












              2








              2







              Use tr to translate the comma to a newline:



              echo "field1,field2,field3,field4" | tr "," "n"


              This is likely faster than using awk, though if you insist, you could do:



              echo "field1,field2,field3,field4" | awk 'gsub(",","n");print'


              From the GNU awk documentation:




              gsub(regexp, replacement [, target])



              Search target for all of the longest, leftmost, nonoverlapping matching substrings it can find and replace them with replacement. The ‘g’ in gsub() stands for “global,” which means replace everywhere.







              share|improve this answer















              Use tr to translate the comma to a newline:



              echo "field1,field2,field3,field4" | tr "," "n"


              This is likely faster than using awk, though if you insist, you could do:



              echo "field1,field2,field3,field4" | awk 'gsub(",","n");print'


              From the GNU awk documentation:




              gsub(regexp, replacement [, target])



              Search target for all of the longest, leftmost, nonoverlapping matching substrings it can find and replace them with replacement. The ‘g’ in gsub() stands for “global,” which means replace everywhere.








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 11 hours ago

























              answered 11 hours ago









              JRFergusonJRFerguson

              10.3k32432




              10.3k32432












              • Thanks, the tr solution is just what i needed

                – Santi
                10 hours ago

















              • Thanks, the tr solution is just what i needed

                – Santi
                10 hours ago
















              Thanks, the tr solution is just what i needed

              – Santi
              10 hours ago





              Thanks, the tr solution is just what i needed

              – Santi
              10 hours ago











              2














              Using bash and csvformat from the csvkit collection to change the field delimiter from a comma to a newline:



              $ csvformat -D $'n' file
              field1
              field2
              field3
              field4


              This is assuming that the input in file is properly formatted CSV. This would also properly handle embedded commas:



              $ cat file
              "field,1",field2,field3,field4
              $ csvformat -D $'n' file
              field,1
              field2
              field3
              field4





              share|improve this answer



























                2














                Using bash and csvformat from the csvkit collection to change the field delimiter from a comma to a newline:



                $ csvformat -D $'n' file
                field1
                field2
                field3
                field4


                This is assuming that the input in file is properly formatted CSV. This would also properly handle embedded commas:



                $ cat file
                "field,1",field2,field3,field4
                $ csvformat -D $'n' file
                field,1
                field2
                field3
                field4





                share|improve this answer

























                  2












                  2








                  2







                  Using bash and csvformat from the csvkit collection to change the field delimiter from a comma to a newline:



                  $ csvformat -D $'n' file
                  field1
                  field2
                  field3
                  field4


                  This is assuming that the input in file is properly formatted CSV. This would also properly handle embedded commas:



                  $ cat file
                  "field,1",field2,field3,field4
                  $ csvformat -D $'n' file
                  field,1
                  field2
                  field3
                  field4





                  share|improve this answer













                  Using bash and csvformat from the csvkit collection to change the field delimiter from a comma to a newline:



                  $ csvformat -D $'n' file
                  field1
                  field2
                  field3
                  field4


                  This is assuming that the input in file is properly formatted CSV. This would also properly handle embedded commas:



                  $ cat file
                  "field,1",field2,field3,field4
                  $ csvformat -D $'n' file
                  field,1
                  field2
                  field3
                  field4






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 11 hours ago









                  KusalanandaKusalananda

                  136k17257425




                  136k17257425




















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









                      draft saved

                      draft discarded


















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












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











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














                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506987%2fhow-can-i-use-awk-to-break-line-content-into-multiple-lines-using-a-separator%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                      Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                      Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.