How do I search for a CSV token in another file?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm using bash shell. I want to parse one CSV file "A", search for that string in CSV file "B", and then output the value from the first column of the matching row in CSV file B. So I tried



while IFS=, read -r col1 name col3 col4 col5
do
echo "I got:$name|$col5"
value=`grep $name /tmp/accounts_created.csv | cut -d, -f$0`
echo "value:$value n"
done < ~/Downloads/all_data.csv


but for some reason this isn't working out, despite the fact I know there is matching data in both files. Is there a better way to be doing this?










share|improve this question

















  • 1




    You didn't show any sample data. You should investigate the join command
    – glenn jackman
    Sep 25 '17 at 17:41










  • The better way is to use a CSV parser. For "small" data you might look f.i. at csvkit.
    – Satō Katsura
    Sep 25 '17 at 19:42














up vote
0
down vote

favorite












I'm using bash shell. I want to parse one CSV file "A", search for that string in CSV file "B", and then output the value from the first column of the matching row in CSV file B. So I tried



while IFS=, read -r col1 name col3 col4 col5
do
echo "I got:$name|$col5"
value=`grep $name /tmp/accounts_created.csv | cut -d, -f$0`
echo "value:$value n"
done < ~/Downloads/all_data.csv


but for some reason this isn't working out, despite the fact I know there is matching data in both files. Is there a better way to be doing this?










share|improve this question

















  • 1




    You didn't show any sample data. You should investigate the join command
    – glenn jackman
    Sep 25 '17 at 17:41










  • The better way is to use a CSV parser. For "small" data you might look f.i. at csvkit.
    – Satō Katsura
    Sep 25 '17 at 19:42












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm using bash shell. I want to parse one CSV file "A", search for that string in CSV file "B", and then output the value from the first column of the matching row in CSV file B. So I tried



while IFS=, read -r col1 name col3 col4 col5
do
echo "I got:$name|$col5"
value=`grep $name /tmp/accounts_created.csv | cut -d, -f$0`
echo "value:$value n"
done < ~/Downloads/all_data.csv


but for some reason this isn't working out, despite the fact I know there is matching data in both files. Is there a better way to be doing this?










share|improve this question













I'm using bash shell. I want to parse one CSV file "A", search for that string in CSV file "B", and then output the value from the first column of the matching row in CSV file B. So I tried



while IFS=, read -r col1 name col3 col4 col5
do
echo "I got:$name|$col5"
value=`grep $name /tmp/accounts_created.csv | cut -d, -f$0`
echo "value:$value n"
done < ~/Downloads/all_data.csv


but for some reason this isn't working out, despite the fact I know there is matching data in both files. Is there a better way to be doing this?







bash shell-script grep csv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 25 '17 at 17:17









Dave

367828




367828







  • 1




    You didn't show any sample data. You should investigate the join command
    – glenn jackman
    Sep 25 '17 at 17:41










  • The better way is to use a CSV parser. For "small" data you might look f.i. at csvkit.
    – Satō Katsura
    Sep 25 '17 at 19:42












  • 1




    You didn't show any sample data. You should investigate the join command
    – glenn jackman
    Sep 25 '17 at 17:41










  • The better way is to use a CSV parser. For "small" data you might look f.i. at csvkit.
    – Satō Katsura
    Sep 25 '17 at 19:42







1




1




You didn't show any sample data. You should investigate the join command
– glenn jackman
Sep 25 '17 at 17:41




You didn't show any sample data. You should investigate the join command
– glenn jackman
Sep 25 '17 at 17:41












The better way is to use a CSV parser. For "small" data you might look f.i. at csvkit.
– Satō Katsura
Sep 25 '17 at 19:42




The better way is to use a CSV parser. For "small" data you might look f.i. at csvkit.
– Satō Katsura
Sep 25 '17 at 19:42










1 Answer
1






active

oldest

votes

















up vote
0
down vote













As what I'm understanding, you only need awk.



awk -F, 'NR==FNRseen[$2]=1;next /seen[$2] ~ $0/print $1
' ~/Downloads/all_data.csv /tmp/accounts_created.csv





share|improve this answer




















  • Does awk deal with CSV formatting? THat is, one can't always split on a "," with CSVs since some cells may contain commas in them.
    – Dave
    Sep 25 '17 at 17:41










  • Yes, so we need sample input(s) and your expected output
    – Î±Ò“sнιη
    Sep 25 '17 at 17:43










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f394361%2fhow-do-i-search-for-a-csv-token-in-another-file%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













As what I'm understanding, you only need awk.



awk -F, 'NR==FNRseen[$2]=1;next /seen[$2] ~ $0/print $1
' ~/Downloads/all_data.csv /tmp/accounts_created.csv





share|improve this answer




















  • Does awk deal with CSV formatting? THat is, one can't always split on a "," with CSVs since some cells may contain commas in them.
    – Dave
    Sep 25 '17 at 17:41










  • Yes, so we need sample input(s) and your expected output
    – Î±Ò“sнιη
    Sep 25 '17 at 17:43














up vote
0
down vote













As what I'm understanding, you only need awk.



awk -F, 'NR==FNRseen[$2]=1;next /seen[$2] ~ $0/print $1
' ~/Downloads/all_data.csv /tmp/accounts_created.csv





share|improve this answer




















  • Does awk deal with CSV formatting? THat is, one can't always split on a "," with CSVs since some cells may contain commas in them.
    – Dave
    Sep 25 '17 at 17:41










  • Yes, so we need sample input(s) and your expected output
    – Î±Ò“sнιη
    Sep 25 '17 at 17:43












up vote
0
down vote










up vote
0
down vote









As what I'm understanding, you only need awk.



awk -F, 'NR==FNRseen[$2]=1;next /seen[$2] ~ $0/print $1
' ~/Downloads/all_data.csv /tmp/accounts_created.csv





share|improve this answer












As what I'm understanding, you only need awk.



awk -F, 'NR==FNRseen[$2]=1;next /seen[$2] ~ $0/print $1
' ~/Downloads/all_data.csv /tmp/accounts_created.csv






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 25 '17 at 17:34









αғsнιη

15.7k92563




15.7k92563











  • Does awk deal with CSV formatting? THat is, one can't always split on a "," with CSVs since some cells may contain commas in them.
    – Dave
    Sep 25 '17 at 17:41










  • Yes, so we need sample input(s) and your expected output
    – Î±Ò“sнιη
    Sep 25 '17 at 17:43
















  • Does awk deal with CSV formatting? THat is, one can't always split on a "," with CSVs since some cells may contain commas in them.
    – Dave
    Sep 25 '17 at 17:41










  • Yes, so we need sample input(s) and your expected output
    – Î±Ò“sнιη
    Sep 25 '17 at 17:43















Does awk deal with CSV formatting? THat is, one can't always split on a "," with CSVs since some cells may contain commas in them.
– Dave
Sep 25 '17 at 17:41




Does awk deal with CSV formatting? THat is, one can't always split on a "," with CSVs since some cells may contain commas in them.
– Dave
Sep 25 '17 at 17:41












Yes, so we need sample input(s) and your expected output
– Î±Ò“sнιη
Sep 25 '17 at 17:43




Yes, so we need sample input(s) and your expected output
– Î±Ò“sнιη
Sep 25 '17 at 17:43

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394361%2fhow-do-i-search-for-a-csv-token-in-another-file%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?