Conversation
Notices
-
Embed this notice
Dave Morriss (perloid@mastodon.sdf.org)'s status on Saturday, 11-Mar-2023 00:23:41 JST Dave Morriss - clacke likes this.
-
Embed this notice
Tinker ☀️ (tinker@infosec.exchange)'s status on Saturday, 11-Mar-2023 00:23:44 JST Tinker ☀️ @null - See I've been using awk for a while now, but really only for rudimentary uses. I reaaaalllly need and want to dive in fully.
Thank you for this example! I'll run with it.
-
Embed this notice
i am root (null@puddle.town)'s status on Saturday, 11-Mar-2023 00:23:45 JST i am root -F',' specifies the field separator as a comma
NR==FNR{a[$1]=$2; next} reads the first file (file2.csv) and stores its second field in an array a indexed by the first field
{print $0","a[$2]} reads the second file (file1.csv) and prints each line followed by the corresponding value in the a array indexed by the second field
-
Embed this notice
i am root (null@puddle.town)'s status on Saturday, 11-Mar-2023 00:23:46 JST i am root awk -F',' 'NR==FNR{a[$1]=$2; next} {print $0","a[$2]}' file2.csv file1.csv
-
Embed this notice
Tinker ☀️ (tinker@infosec.exchange)'s status on Saturday, 11-Mar-2023 00:23:48 JST Tinker ☀️ Bash data parsing question....
I have two csv files. I need to combine them in a certain way. I can't use the 'join' command, as the specific fields I want to match are not perfectly sorted.
Here is an example of the two files:
file1.csv
recipe01,chicken
recipe02,beef
recipe03,chicken
recipe04,fishfile2.csv
chicken,clucks
beef,moos
fish,warblegarbleI need to find a way to create the following file:
file3.csv
recipe01,chicken,clucks
recipe02,beef,moos
recipe03,chicken,clucks
recipe04,fish,warblegarbleAnyone know a good command, program, or script that would do that? Go through field 2 of the first file and match it to field 1 of the second file, and add field 2 of the second file to the line?