First Match - awkMultiple pattern match and print in single lineSubstitute values from file1 to file2 awkawk + print lines from the first line until match wordawk multiple pattern match and print in single lineHow can I match a string when not preceded by a digit using awk?awk in solaris 5.8 / get value from two fields/linesTrouble with awk matchusing awk to print lines from one match through a second instance of a separate matchHow to remove duplicate lines in a CSV based on first field, and 1st n chars of 2nd field?Joining entries based off of column using awk/join

Popcorn is the only acceptable snack to consume while watching a movie

Did this character show any indication of wanting to rule before S8E6?

How to melt snow without fire or body heat?

Is it rude to call a professor by their last name with no prefix in a non-academic setting?

Who is in charge of Wakanda?

How to ignore kerning of underbrace in math mode

Efficient Algorithm for the boundary of a set of tiles

Adding edges to a TreeForm of an expression

Python program to take in two strings and print the larger string

How did NASA Langley end up with the first 737?

Do I need full recovery mode when I have multiple daily backup?

Have 1.5% of all nuclear reactors ever built melted down?

How can I select seats on Amtrak train?

What was the idiom for something that we take without a doubt?

The roles understanding in the agile development / Is the PO always right?

Construct a word ladder

Is there a simple example that empirical evidence is misleading?

Can my floppy disk still work without a shutter spring?

Is the field of q-series 'dead'?

Need to read my home electrical meter

Why does this if-statement combining assignment and an equality check return true?

Specific alignment within beginalign environment

Are black holes spherical during merger?

Can I tell a prospective employee that everyone in the team is leaving?



First Match - awk


Multiple pattern match and print in single lineSubstitute values from file1 to file2 awkawk + print lines from the first line until match wordawk multiple pattern match and print in single lineHow can I match a string when not preceded by a digit using awk?awk in solaris 5.8 / get value from two fields/linesTrouble with awk matchusing awk to print lines from one match through a second instance of a separate matchHow to remove duplicate lines in a CSV based on first field, and 1st n chars of 2nd field?Joining entries based off of column using awk/join






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








1















consider file having values:



foo
boo
too


and another one:



foo,1
foo,2
boo,1
soo,1


How to get only first match from the 2nd file, where output will be:



foo,1
boo,1









share|improve this question




























    1















    consider file having values:



    foo
    boo
    too


    and another one:



    foo,1
    foo,2
    boo,1
    soo,1


    How to get only first match from the 2nd file, where output will be:



    foo,1
    boo,1









    share|improve this question
























      1












      1








      1








      consider file having values:



      foo
      boo
      too


      and another one:



      foo,1
      foo,2
      boo,1
      soo,1


      How to get only first match from the 2nd file, where output will be:



      foo,1
      boo,1









      share|improve this question














      consider file having values:



      foo
      boo
      too


      and another one:



      foo,1
      foo,2
      boo,1
      soo,1


      How to get only first match from the 2nd file, where output will be:



      foo,1
      boo,1






      text-processing awk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 9 hours ago









      Eng7Eng7

      8752822




      8752822




















          4 Answers
          4






          active

          oldest

          votes


















          3














          How about



          $ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
          foo,1
          boo,1





          share|improve this answer






























            3














            A variation of the famous seen idiom.



            awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2





            share|improve this answer






























              1














              Not actually awk, but it works. And I suppose it allows for easy extension.



              #!/usr/bin/env bash

              while IFS= read -r line; do
              grep -m1 "$line" "$2"
              done < "$1"


              $ ./script.sh file1 file2


              Took the reading line-by-line from https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable.

              Then it's just 'find first match with content of line in file2'






              share|improve this answer








              New contributor



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


























                0














                I Have also used awk but with different method



                command



                awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '


                output



                awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '
                foo,1
                boo,1





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



                  );













                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f520630%2ffirst-match-awk%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  3














                  How about



                  $ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
                  foo,1
                  boo,1





                  share|improve this answer



























                    3














                    How about



                    $ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
                    foo,1
                    boo,1





                    share|improve this answer

























                      3












                      3








                      3







                      How about



                      $ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
                      foo,1
                      boo,1





                      share|improve this answer













                      How about



                      $ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
                      foo,1
                      boo,1






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 8 hours ago









                      steeldriversteeldriver

                      39k45491




                      39k45491























                          3














                          A variation of the famous seen idiom.



                          awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2





                          share|improve this answer



























                            3














                            A variation of the famous seen idiom.



                            awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2





                            share|improve this answer

























                              3












                              3








                              3







                              A variation of the famous seen idiom.



                              awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2





                              share|improve this answer













                              A variation of the famous seen idiom.



                              awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 8 hours ago









                              dedowsdidedowsdi

                              58916




                              58916





















                                  1














                                  Not actually awk, but it works. And I suppose it allows for easy extension.



                                  #!/usr/bin/env bash

                                  while IFS= read -r line; do
                                  grep -m1 "$line" "$2"
                                  done < "$1"


                                  $ ./script.sh file1 file2


                                  Took the reading line-by-line from https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable.

                                  Then it's just 'find first match with content of line in file2'






                                  share|improve this answer








                                  New contributor



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























                                    1














                                    Not actually awk, but it works. And I suppose it allows for easy extension.



                                    #!/usr/bin/env bash

                                    while IFS= read -r line; do
                                    grep -m1 "$line" "$2"
                                    done < "$1"


                                    $ ./script.sh file1 file2


                                    Took the reading line-by-line from https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable.

                                    Then it's just 'find first match with content of line in file2'






                                    share|improve this answer








                                    New contributor



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





















                                      1












                                      1








                                      1







                                      Not actually awk, but it works. And I suppose it allows for easy extension.



                                      #!/usr/bin/env bash

                                      while IFS= read -r line; do
                                      grep -m1 "$line" "$2"
                                      done < "$1"


                                      $ ./script.sh file1 file2


                                      Took the reading line-by-line from https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable.

                                      Then it's just 'find first match with content of line in file2'






                                      share|improve this answer








                                      New contributor



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









                                      Not actually awk, but it works. And I suppose it allows for easy extension.



                                      #!/usr/bin/env bash

                                      while IFS= read -r line; do
                                      grep -m1 "$line" "$2"
                                      done < "$1"


                                      $ ./script.sh file1 file2


                                      Took the reading line-by-line from https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable.

                                      Then it's just 'find first match with content of line in file2'







                                      share|improve this answer








                                      New contributor



                                      user2966394 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 answer



                                      share|improve this answer






                                      New contributor



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








                                      answered 8 hours ago









                                      user2966394user2966394

                                      144




                                      144




                                      New contributor



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




                                      New contributor




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























                                          0














                                          I Have also used awk but with different method



                                          command



                                          awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '


                                          output



                                          awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '
                                          foo,1
                                          boo,1





                                          share|improve this answer



























                                            0














                                            I Have also used awk but with different method



                                            command



                                            awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '


                                            output



                                            awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '
                                            foo,1
                                            boo,1





                                            share|improve this answer

























                                              0












                                              0








                                              0







                                              I Have also used awk but with different method



                                              command



                                              awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '


                                              output



                                              awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '
                                              foo,1
                                              boo,1





                                              share|improve this answer













                                              I Have also used awk but with different method



                                              command



                                              awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '


                                              output



                                              awk -F "," 'NR==FNRa[$1];next($1 in a)print $0' file1.txt file2.txt| awk -F "," 'if (!seen[$1]++)print '
                                              foo,1
                                              boo,1






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 6 hours ago









                                              Praveen Kumar BSPraveen Kumar BS

                                              1,9012311




                                              1,9012311



























                                                  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%2f520630%2ffirst-match-awk%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

                                                  Log på Navigationsmenu

                                                  Creating second map without labels using QGIS?How to lock map labels for inset map in Print Composer?How to Force the Showing of Labels of a Vector File in QGISQGIS Valmiera, Labels only show for part of polygonsRemoving duplicate point labels in QGISLabeling every feature using QGIS?Show labels for point features outside map canvasAbbreviate Road Labels in QGIS only when requiredExporting map from composer in QGIS - text labels have moved in output?How to make sure labels in qgis turn up in layout map?Writing label expression with ArcMap and If then Statement?

                                                  Nuuk Indholdsfortegnelse Etyomologi | Historie | Geografi | Transport og infrastruktur | Politik og administration | Uddannelsesinstitutioner | Kultur | Venskabsbyer | Noter | Eksterne henvisninger | Se også | Navigationsmenuwww.sermersooq.gl64°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.75064°10′N 51°45′V / 64.167°N 51.750°V / 64.167; -51.750DMI - KlimanormalerSalmonsen, s. 850Grønlands Naturinstitut undersøger rensdyr i Akia og Maniitsoq foråret 2008Grønlands NaturinstitutNy vej til Qinngorput indviet i dagAntallet af biler i Nuuk må begrænsesNy taxacentral mødt med demonstrationKøreplan. Rute 1, 2 og 3SnescootersporNuukNord er for storSkoler i Kommuneqarfik SermersooqAtuarfik Samuel KleinschmidtKangillinguit AtuarfiatNuussuup AtuarfiaNuuk Internationale FriskoleIlinniarfissuaq, Grønlands SeminariumLedelseÅrsberetning for 2008Kunst og arkitekturÅrsberetning for 2008Julie om naturenNuuk KunstmuseumSilamiutGrønlands Nationalmuseum og ArkivStatistisk ÅrbogGrønlands LandsbibliotekStore koncerter på stribeVandhund nummer 1.000.000Kommuneqarfik Sermersooq – MalikForsidenVenskabsbyerLyngby-Taarbæk i GrønlandArctic Business NetworkWinter Cities 2008 i NuukDagligt opdaterede satellitbilleder fra NuukområdetKommuneqarfik Sermersooqs hjemmesideTurist i NuukGrønlands Statistiks databankGrønlands Hjemmestyres valgresultaterrrWorldCat124325457671310-5