Skip to main content
deleted 66 characters in body; edited tags
Source Link
αғsнιη
  • 42k
  • 17
  • 75
  • 118

I want find patterns from csv1 (column1) in csv2 (anywhere) and exchange them with patterns from csv1 (column2).

Like following:

-csv1-

column1 column2
AA edc
BB ysc
CC cds
DD erg

...etc

-csv2-

column1 column2 column3 ...etc (many more columns)
BB kj waa pds
xsd tkp etp AA
xrg AA DD CC
ggg rko blb DD
tpp apt CC www

The solution is something like in this post... How to compare column in two different csv file and replace column from another file

suggesting:

$ awk ' BEGIN { FS=OFS="," } NR==FNR { map[$1] = $2; next } (FNR>1) && ($4 in map) { $4 = map[$4] } 1' file2 file1 

This one would work for me. I just need to specify to search through all columns, not just the 4th one.

Please, is there any simple solution? I bet it is :)

Kajman

I want find patterns from csv1 (column1) in csv2 (anywhere) and exchange them with patterns from csv1 (column2).

Like following:

-csv1-

column1 column2
AA edc
BB ysc
CC cds
DD erg

...etc

-csv2-

column1 column2 column3 ...etc (many more columns)
BB kj waa pds
xsd tkp etp AA
xrg AA DD CC
ggg rko blb DD
tpp apt CC www

The solution is something like in this post... How to compare column in two different csv file and replace column from another file

suggesting:

$ awk ' BEGIN { FS=OFS="," } NR==FNR { map[$1] = $2; next } (FNR>1) && ($4 in map) { $4 = map[$4] } 1' file2 file1 

This one would work for me. I just need to specify to search through all columns, not just the 4th one.

Please, is there any simple solution? I bet it is :)

Kajman

I want find patterns from csv1 (column1) in csv2 (anywhere) and exchange them with patterns from csv1 (column2).

Like following:

-csv1-

column1 column2
AA edc
BB ysc
CC cds
DD erg

...etc

-csv2-

column1 column2 column3 ...etc (many more columns)
BB kj waa pds
xsd tkp etp AA
xrg AA DD CC
ggg rko blb DD
tpp apt CC www

The solution is something like in this post... How to compare column in two different csv file and replace column from another file

suggesting:

$ awk ' BEGIN { FS=OFS="," } NR==FNR { map[$1] = $2; next } (FNR>1) && ($4 in map) { $4 = map[$4] } 1' file2 file1 

This one would work for me. I just need to specify to search through all columns, not just the 4th one.

Source Link

How to exchange matching patterns in a csv file using another two-column csv table

I want find patterns from csv1 (column1) in csv2 (anywhere) and exchange them with patterns from csv1 (column2).

Like following:

-csv1-

column1 column2
AA edc
BB ysc
CC cds
DD erg

...etc

-csv2-

column1 column2 column3 ...etc (many more columns)
BB kj waa pds
xsd tkp etp AA
xrg AA DD CC
ggg rko blb DD
tpp apt CC www

The solution is something like in this post... How to compare column in two different csv file and replace column from another file

suggesting:

$ awk ' BEGIN { FS=OFS="," } NR==FNR { map[$1] = $2; next } (FNR>1) && ($4 in map) { $4 = map[$4] } 1' file2 file1 

This one would work for me. I just need to specify to search through all columns, not just the 4th one.

Please, is there any simple solution? I bet it is :)

Kajman