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

Do photons bend spacetime or not?

How to reverse input order?

Did 20% of US soldiers in Vietnam use heroin, 95% of whom quit afterwards?

Count Even Digits In Number

Can I summon an otherworldly creature with Gate without knowing it's true name?

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

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

Parallel fifths in the orchestra

Open office space - complaints for noise - how to respond

What does 気楽 mean when attached to ビール or お酒?

Are black holes spherical during merger?

Convert Byte array into collection of items of different types

How to cut a climbing rope?

What was Stree?

Website returning plaintext password

Need to read my home electrical meter

What are the meaning and grammar of "Crying isn't like you"?

How to ignore kerning of underbrace in math mode

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

Is the Unsullied name meant to be ironic? How did it come to be?

Why did Jon Snow do this immoral act if he is so honorable?

The art of clickbait captions

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

What does $!# mean in Shell scripting?



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;








2















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




























    2















    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
























      2












      2








      2








      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

      8802822




      8802822




















          4 Answers
          4






          active

          oldest

          votes


















          4














          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






























            4














            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.


























                1














                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









                  4














                  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



























                    4














                    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

























                      4












                      4








                      4







                      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 9 hours ago









                      steeldriversteeldriver

                      39.1k45491




                      39.1k45491























                          4














                          A variation of the famous seen idiom.



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





                          share|improve this answer



























                            4














                            A variation of the famous seen idiom.



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





                            share|improve this answer

























                              4












                              4








                              4







                              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

                              59916




                              59916





















                                  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.























                                          1














                                          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



























                                            1














                                            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

























                                              1












                                              1








                                              1







                                              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,9112311




                                              1,9112311



























                                                  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

                                                  Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                                  Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                                  François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480