Comma separated words into new linesExpanding comma-separated list into separate linesAwk/grep/sed get comma...

Rail-to-rail op-amp only reaches 90% of VCC, works sometimes, not everytime

Confused with atmospheric pressure equals plastic balloon’s inner pressure

How (un)safe is it to ride barefoot?

Should I refuse to be named as co-author of a low quality paper?

What do you call the action of "describing events as they happen" like sports anchors do?

Assigning function to function pointer, const argument correctness?

Canada travel to US using Global Entry

Was planting UN flag on Moon ever discussed?

Could a person damage a jet airliner - from the outside - with their bare hands?

Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?

The origin of the Russian proverb about two hares

Make Gimbap cutter

Convert only certain words to lowercase

Proving that a Russian cryptographic standard is too structured

What STL algorithm can determine if exactly one item in a container satisfies a predicate?

What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?

C++ logging library

What would be the way to say "just saying" in German? (Not the literal translation)

Is Jesus the last Prophet?

How far would a landing Airbus A380 go until it stops with no brakes?

Grep Match and extract

Do you have to have figures when playing D&D?

Was Self-modifying-code possible just using BASIC?

Do you need to let the DM know when you are multiclassing?



Comma separated words into new lines


Expanding comma-separated list into separate linesAwk/grep/sed get comma separated list of numbers from lines of textChange script to use whiptail instead of zenityjoin multiple lines based on column1Assigning files key words to easily find them laterProcessing table with comma separated values in different columnsMerge jq output into a comma separated stringGrep Ternary Curl ReponsePassing the output of a command to another in one lineHow to convert a 3 column csv file into a table (or matrix)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















Hi I have an input file looks like this



N1518    AMP,AUG,AZM,CHL 
N1520 AZM,NAL
N1524 AMP,NAL,STR
......


I'm trying to convert it to



N1518    AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1520 NAL
N1524 AMP
N1524 NAL
N1524 STR
....


Is there an one liner to do this?










share|improve this question







New contributor



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


























    0















    Hi I have an input file looks like this



    N1518    AMP,AUG,AZM,CHL 
    N1520 AZM,NAL
    N1524 AMP,NAL,STR
    ......


    I'm trying to convert it to



    N1518    AMP
    N1518 AUG
    N1518 AZM
    N1518 CHL
    N1520 AZM
    N1520 NAL
    N1524 AMP
    N1524 NAL
    N1524 STR
    ....


    Is there an one liner to do this?










    share|improve this question







    New contributor



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






















      0












      0








      0








      Hi I have an input file looks like this



      N1518    AMP,AUG,AZM,CHL 
      N1520 AZM,NAL
      N1524 AMP,NAL,STR
      ......


      I'm trying to convert it to



      N1518    AMP
      N1518 AUG
      N1518 AZM
      N1518 CHL
      N1520 AZM
      N1520 NAL
      N1524 AMP
      N1524 NAL
      N1524 STR
      ....


      Is there an one liner to do this?










      share|improve this question







      New contributor



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











      Hi I have an input file looks like this



      N1518    AMP,AUG,AZM,CHL 
      N1520 AZM,NAL
      N1524 AMP,NAL,STR
      ......


      I'm trying to convert it to



      N1518    AMP
      N1518 AUG
      N1518 AZM
      N1518 CHL
      N1520 AZM
      N1520 NAL
      N1524 AMP
      N1524 NAL
      N1524 STR
      ....


      Is there an one liner to do this?







      command-line






      share|improve this question







      New contributor



      user357073 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



      user357073 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






      New contributor



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








      asked 1 hour ago









      user357073user357073

      31




      31




      New contributor



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




      New contributor




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
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You can use awk with multiple separators, and then iterate over fields to print the columns.



          awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file


          Explanation:



          -F'[ ,]+' : This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.



          for (i=2;i<=NF;i++) : loops over all columns starting from the second one, because we have to print the first column repeatedly.



          printf "%s %sn",$1,$i; : prints a line with the first column and the ith column






          share|improve this answer
























          • Works. Just replaced the space with tab since it is tab separated file. Nice explanation.

            – user357073
            54 mins ago





















          0














          Try this,



          awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
          N1518 AMP
          N1518 AUG
          N1518 AZM
          N1518 CHL
          N1520 AZM
          N1524 AMP
          N1524 NAL





          share|improve this answer





















          • 1





            Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`

            – user357073
            56 mins ago












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


          }
          });






          user357073 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%2f523921%2fcomma-separated-words-into-new-lines%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can use awk with multiple separators, and then iterate over fields to print the columns.



          awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file


          Explanation:



          -F'[ ,]+' : This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.



          for (i=2;i<=NF;i++) : loops over all columns starting from the second one, because we have to print the first column repeatedly.



          printf "%s %sn",$1,$i; : prints a line with the first column and the ith column






          share|improve this answer
























          • Works. Just replaced the space with tab since it is tab separated file. Nice explanation.

            – user357073
            54 mins ago


















          0














          You can use awk with multiple separators, and then iterate over fields to print the columns.



          awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file


          Explanation:



          -F'[ ,]+' : This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.



          for (i=2;i<=NF;i++) : loops over all columns starting from the second one, because we have to print the first column repeatedly.



          printf "%s %sn",$1,$i; : prints a line with the first column and the ith column






          share|improve this answer
























          • Works. Just replaced the space with tab since it is tab separated file. Nice explanation.

            – user357073
            54 mins ago
















          0












          0








          0







          You can use awk with multiple separators, and then iterate over fields to print the columns.



          awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file


          Explanation:



          -F'[ ,]+' : This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.



          for (i=2;i<=NF;i++) : loops over all columns starting from the second one, because we have to print the first column repeatedly.



          printf "%s %sn",$1,$i; : prints a line with the first column and the ith column






          share|improve this answer













          You can use awk with multiple separators, and then iterate over fields to print the columns.



          awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file


          Explanation:



          -F'[ ,]+' : This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.



          for (i=2;i<=NF;i++) : loops over all columns starting from the second one, because we have to print the first column repeatedly.



          printf "%s %sn",$1,$i; : prints a line with the first column and the ith column







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          amisaxamisax

          1,636615




          1,636615













          • Works. Just replaced the space with tab since it is tab separated file. Nice explanation.

            – user357073
            54 mins ago





















          • Works. Just replaced the space with tab since it is tab separated file. Nice explanation.

            – user357073
            54 mins ago



















          Works. Just replaced the space with tab since it is tab separated file. Nice explanation.

          – user357073
          54 mins ago







          Works. Just replaced the space with tab since it is tab separated file. Nice explanation.

          – user357073
          54 mins ago















          0














          Try this,



          awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
          N1518 AMP
          N1518 AUG
          N1518 AZM
          N1518 CHL
          N1520 AZM
          N1524 AMP
          N1524 NAL





          share|improve this answer





















          • 1





            Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`

            – user357073
            56 mins ago
















          0














          Try this,



          awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
          N1518 AMP
          N1518 AUG
          N1518 AZM
          N1518 CHL
          N1520 AZM
          N1524 AMP
          N1524 NAL





          share|improve this answer





















          • 1





            Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`

            – user357073
            56 mins ago














          0












          0








          0







          Try this,



          awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
          N1518 AMP
          N1518 AUG
          N1518 AZM
          N1518 CHL
          N1520 AZM
          N1524 AMP
          N1524 NAL





          share|improve this answer















          Try this,



          awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
          N1518 AMP
          N1518 AUG
          N1518 AZM
          N1518 CHL
          N1520 AZM
          N1524 AMP
          N1524 NAL






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 57 mins ago

























          answered 1 hour ago









          msp9011msp9011

          5,08244269




          5,08244269








          • 1





            Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`

            – user357073
            56 mins ago














          • 1





            Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`

            – user357073
            56 mins ago








          1




          1





          Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`

          – user357073
          56 mins ago





          Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`

          – user357073
          56 mins ago










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










          draft saved

          draft discarded


















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













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












          user357073 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%2f523921%2fcomma-separated-words-into-new-lines%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

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...