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;
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
add a comment |
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
add a comment |
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
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
text-processing awk
asked 9 hours ago
Eng7Eng7
8802822
8802822
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
How about
$ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
foo,1
boo,1
add a comment |
A variation of the famous seen idiom.
awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2
add a comment |
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'
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.
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
How about
$ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
foo,1
boo,1
add a comment |
How about
$ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
foo,1
boo,1
add a comment |
How about
$ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
foo,1
boo,1
How about
$ awk -F, 'NR==FNR a[$1]; next $1 in a print; delete a[$1]' file1 file2
foo,1
boo,1
answered 9 hours ago
steeldriversteeldriver
39.1k45491
39.1k45491
add a comment |
add a comment |
A variation of the famous seen idiom.
awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2
add a comment |
A variation of the famous seen idiom.
awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2
add a comment |
A variation of the famous seen idiom.
awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2
A variation of the famous seen idiom.
awk -F, 'FNR==NRa[$1]=1;next a[$1]++==1' file1 file2
answered 8 hours ago
dedowsdidedowsdi
59916
59916
add a comment |
add a comment |
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'
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.
add a comment |
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'
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.
add a comment |
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'
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'
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.
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.
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered 6 hours ago
Praveen Kumar BSPraveen Kumar BS
1,9112311
1,9112311
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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