Parsing CSV with AWK to Produce HTML Outputuniq a csv file ignoring a column, awk maybe?awk with if statementsHow to print all fields containing one of two strings in a table with awkCount the number of occurrences of a column value in a TSV file with AWKIgnore delimiter present inside quotesHow to transform this data into assignations using awk or other?awk- Combine 2 .csv files based on a matching columnCSV file: Group and sum values based on first pattern of each valueHaving trouble parsing a csv file from the commandlinenmap output in CSV format sorted by IP address

Is having a hidden directory under /etc safe?

Are there mythical creatures in the world of Game of Thrones?

If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?

Constructing a CCY Gate

How to decline physical affection from a child whose parents are pressuring them?

Can an old DSLR be upgraded to match modern smartphone image quality

What are the problems in teaching guitar via Skype?

Is the world in Game of Thrones spherical or flat?

Joist hangers to use for rough cut 2x8 (2 3/4" x 8 3/4")?

Could a soul from the Soulmonger be restored in the ToA campaign after this event?

How to detach yourself from a character you're going to kill?

Cryptography and patents

What caused the tendency for conservatives to not support climate change regulations?

How can I offer a test ride while selling a bike?

Question about IV chord in minor key

Accidentally cashed a check twice

The oldest tradition stopped before it got back to him

Why does my electric oven present the option of 40A and 50A breakers?

Order by does not work as I expect

California: "For quality assurance, this phone call is being recorded"

When was the word "ambigu" first used with the sense of "meal with all items served at the same time"?

What if you don't bring your credit card or debit for incidentals?

Creating Fictional Slavic Place Names

What people are called "кабан" and why?



Parsing CSV with AWK to Produce HTML Output


uniq a csv file ignoring a column, awk maybe?awk with if statementsHow to print all fields containing one of two strings in a table with awkCount the number of occurrences of a column value in a TSV file with AWKIgnore delimiter present inside quotesHow to transform this data into assignations using awk or other?awk- Combine 2 .csv files based on a matching columnCSV file: Group and sum values based on first pattern of each valueHaving trouble parsing a csv file from the commandlinenmap output in CSV format sorted by IP address






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








1















I have a data file with rows of comma-separated fields like this:



United Kingdom, GB, +44


and I want to produce the following output for each line in the file:



<option value="GB">United Kingdom +44</option>


I got as far as follows with awk, but after adding the angle brackets I am getting mangled output:



BEGINFS=","; 

print "<option value="" $2 "">";











share|improve this question






























    1















    I have a data file with rows of comma-separated fields like this:



    United Kingdom, GB, +44


    and I want to produce the following output for each line in the file:



    <option value="GB">United Kingdom +44</option>


    I got as far as follows with awk, but after adding the angle brackets I am getting mangled output:



    BEGINFS=","; 

    print "<option value="" $2 "">";











    share|improve this question


























      1












      1








      1








      I have a data file with rows of comma-separated fields like this:



      United Kingdom, GB, +44


      and I want to produce the following output for each line in the file:



      <option value="GB">United Kingdom +44</option>


      I got as far as follows with awk, but after adding the angle brackets I am getting mangled output:



      BEGINFS=","; 

      print "<option value="" $2 "">";











      share|improve this question
















      I have a data file with rows of comma-separated fields like this:



      United Kingdom, GB, +44


      and I want to produce the following output for each line in the file:



      <option value="GB">United Kingdom +44</option>


      I got as far as follows with awk, but after adding the angle brackets I am getting mangled output:



      BEGINFS=","; 

      print "<option value="" $2 "">";








      awk csv html






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 7 hours ago







      M.K.

















      asked 9 hours ago









      M.K.M.K.

      1114




      1114




















          1 Answer
          1






          active

          oldest

          votes


















          4














          awk's printf function can be easier to use when it comes to embedded quotes.



          awk -F, 'printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          The problem with that is that you also have whitespace between each field. We can use the gsub function to trim each field.



          awk -F, ' +$/,"", $2); printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          Or what's easier is to change our field separator:
          awk -F' *, *' 'printf("%s %sn", $2, $1, $3)'



          If you need to trim multiple fields then it might be better to use a loop or a function (depending on the situation). See https://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk for more info.






          share|improve this answer























          • I don't get the correct output with this. The "</option>" at the end does not appear at the end of each line. It only appears on the last line e.g. </option>alue="+260">Zambia ZM <option value="+263">Zimbabwe ZW</option>

            – M.K.
            7 hours ago






          • 2





            @M.K. looks like your csv has CRLF line delimiters, convert to unix first with dos2unix.

            – Stéphane Chazelas
            7 hours ago











          • @StéphaneChazelas thanks, that was the problem!

            – M.K.
            6 hours 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
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f521786%2fparsing-csv-with-awk-to-produce-html-output%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          awk's printf function can be easier to use when it comes to embedded quotes.



          awk -F, 'printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          The problem with that is that you also have whitespace between each field. We can use the gsub function to trim each field.



          awk -F, ' +$/,"", $2); printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          Or what's easier is to change our field separator:
          awk -F' *, *' 'printf("%s %sn", $2, $1, $3)'



          If you need to trim multiple fields then it might be better to use a loop or a function (depending on the situation). See https://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk for more info.






          share|improve this answer























          • I don't get the correct output with this. The "</option>" at the end does not appear at the end of each line. It only appears on the last line e.g. </option>alue="+260">Zambia ZM <option value="+263">Zimbabwe ZW</option>

            – M.K.
            7 hours ago






          • 2





            @M.K. looks like your csv has CRLF line delimiters, convert to unix first with dos2unix.

            – Stéphane Chazelas
            7 hours ago











          • @StéphaneChazelas thanks, that was the problem!

            – M.K.
            6 hours ago















          4














          awk's printf function can be easier to use when it comes to embedded quotes.



          awk -F, 'printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          The problem with that is that you also have whitespace between each field. We can use the gsub function to trim each field.



          awk -F, ' +$/,"", $2); printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          Or what's easier is to change our field separator:
          awk -F' *, *' 'printf("%s %sn", $2, $1, $3)'



          If you need to trim multiple fields then it might be better to use a loop or a function (depending on the situation). See https://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk for more info.






          share|improve this answer























          • I don't get the correct output with this. The "</option>" at the end does not appear at the end of each line. It only appears on the last line e.g. </option>alue="+260">Zambia ZM <option value="+263">Zimbabwe ZW</option>

            – M.K.
            7 hours ago






          • 2





            @M.K. looks like your csv has CRLF line delimiters, convert to unix first with dos2unix.

            – Stéphane Chazelas
            7 hours ago











          • @StéphaneChazelas thanks, that was the problem!

            – M.K.
            6 hours ago













          4












          4








          4







          awk's printf function can be easier to use when it comes to embedded quotes.



          awk -F, 'printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          The problem with that is that you also have whitespace between each field. We can use the gsub function to trim each field.



          awk -F, ' +$/,"", $2); printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          Or what's easier is to change our field separator:
          awk -F' *, *' 'printf("%s %sn", $2, $1, $3)'



          If you need to trim multiple fields then it might be better to use a loop or a function (depending on the situation). See https://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk for more info.






          share|improve this answer













          awk's printf function can be easier to use when it comes to embedded quotes.



          awk -F, 'printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          The problem with that is that you also have whitespace between each field. We can use the gsub function to trim each field.



          awk -F, ' +$/,"", $2); printf("<option value="%s">%s %s</option>n", $2, $1, $3)'


          Or what's easier is to change our field separator:
          awk -F' *, *' 'printf("%s %sn", $2, $1, $3)'



          If you need to trim multiple fields then it might be better to use a loop or a function (depending on the situation). See https://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk for more info.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 8 hours ago









          DarkHeartDarkHeart

          3,59142541




          3,59142541












          • I don't get the correct output with this. The "</option>" at the end does not appear at the end of each line. It only appears on the last line e.g. </option>alue="+260">Zambia ZM <option value="+263">Zimbabwe ZW</option>

            – M.K.
            7 hours ago






          • 2





            @M.K. looks like your csv has CRLF line delimiters, convert to unix first with dos2unix.

            – Stéphane Chazelas
            7 hours ago











          • @StéphaneChazelas thanks, that was the problem!

            – M.K.
            6 hours ago

















          • I don't get the correct output with this. The "</option>" at the end does not appear at the end of each line. It only appears on the last line e.g. </option>alue="+260">Zambia ZM <option value="+263">Zimbabwe ZW</option>

            – M.K.
            7 hours ago






          • 2





            @M.K. looks like your csv has CRLF line delimiters, convert to unix first with dos2unix.

            – Stéphane Chazelas
            7 hours ago











          • @StéphaneChazelas thanks, that was the problem!

            – M.K.
            6 hours ago
















          I don't get the correct output with this. The "</option>" at the end does not appear at the end of each line. It only appears on the last line e.g. </option>alue="+260">Zambia ZM <option value="+263">Zimbabwe ZW</option>

          – M.K.
          7 hours ago





          I don't get the correct output with this. The "</option>" at the end does not appear at the end of each line. It only appears on the last line e.g. </option>alue="+260">Zambia ZM <option value="+263">Zimbabwe ZW</option>

          – M.K.
          7 hours ago




          2




          2





          @M.K. looks like your csv has CRLF line delimiters, convert to unix first with dos2unix.

          – Stéphane Chazelas
          7 hours ago





          @M.K. looks like your csv has CRLF line delimiters, convert to unix first with dos2unix.

          – Stéphane Chazelas
          7 hours ago













          @StéphaneChazelas thanks, that was the problem!

          – M.K.
          6 hours ago





          @StéphaneChazelas thanks, that was the problem!

          – M.K.
          6 hours ago

















          draft saved

          draft discarded
















































          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%2f521786%2fparsing-csv-with-awk-to-produce-html-output%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

          ParseJSON using SSJSUsing AMPscript with SSJS ActivitiesHow to resubscribe a user in Marketing cloud using SSJS?Pulling Subscriber Status from Lists using SSJSRetrieving Emails using SSJSProblem in updating DE using SSJSUsing SSJS to send single email in Marketing CloudError adding EmailSendDefinition using SSJS

          Кампала Садржај Географија Географија Историја Становништво Привреда Партнерски градови Референце Спољашње везе Мени за навигацију0°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.340°11′ СГШ; 32°20′ ИГД / 0.18° СГШ; 32.34° ИГД / 0.18; 32.34МедијиПодациЗванични веб-сајту

          19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу