How do I search for a CSV token in another file?
Clash 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?
bash shell-script grep csv
add a comment |Â
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?
bash shell-script grep csv
1
You didn't show any sample data. You should investigate thejoin
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
add a comment |Â
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?
bash shell-script grep csv
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
bash shell-script grep csv
asked Sep 25 '17 at 17:17
Dave
367828
367828
1
You didn't show any sample data. You should investigate thejoin
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
add a comment |Â
1
You didn't show any sample data. You should investigate thejoin
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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
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
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
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
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
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