Skip to main content

I need to a add a column in CSV file from an array using awk.

For example,

input.csvinput.csv

a,10
b,11

array = (100 200)array = (100 200)

output.csvoutput.csv should look like

a,10,100
b,11,200

I tried this command but it does not work

awk -F"," 'BEGIN { OFS = "," } {for (x in array) $3=array[x]; print}' input.csv> output.csv

I need to a add a column in CSV file from an array using awk.

For example,

input.csv

a,10
b,11

array = (100 200)

output.csv should look like

a,10,100
b,11,200

I tried this command but it does not work

awk -F"," 'BEGIN { OFS = "," } {for (x in array) $3=array[x]; print}' input.csv> output.csv

I need to a add a column in CSV file from an array using awk.

For example,

input.csv

a,10
b,11

array = (100 200)

output.csv should look like

a,10,100
b,11,200

I tried this command but it does not work

awk -F"," 'BEGIN { OFS = "," } {for (x in array) $3=array[x]; print}' input.csv> output.csv
added 24 characters in body; edited tags
Source Link
jimmij
  • 48.7k
  • 20
  • 136
  • 141

I need to a add a column in CSV file from an array using awk.

For example,

input.csv a,10 b,11

a,10
b,11

array = (100 200)

output.csv should look like a,10,100 b,11,200

a,10,100
b,11,200

I tried this command but it does not work

awk -F"," 'BEGIN { OFS = "," } {for (x in array) $3=array[x]; print}' input.csv> output.csv

awk -F"," 'BEGIN { OFS = "," } {for (x in array) $3=array[x]; print}' input.csv> output.csv

I need to a add a column in CSV file from an array using awk.

For example,

input.csv a,10 b,11

array = (100 200)

output.csv should look like a,10,100 b,11,200

I tried this command but it does not work

awk -F"," 'BEGIN { OFS = "," } {for (x in array) $3=array[x]; print}' input.csv> output.csv

I need to a add a column in CSV file from an array using awk.

For example,

input.csv

a,10
b,11

array = (100 200)

output.csv should look like

a,10,100
b,11,200

I tried this command but it does not work

awk -F"," 'BEGIN { OFS = "," } {for (x in array) $3=array[x]; print}' input.csv> output.csv
Source Link
Rauf
  • 319
  • 1
  • 3
  • 4

adding column in CSV file using awk

I need to a add a column in CSV file from an array using awk.

For example,

input.csv a,10 b,11

array = (100 200)

output.csv should look like a,10,100 b,11,200

I tried this command but it does not work

awk -F"," 'BEGIN { OFS = "," } {for (x in array) $3=array[x]; print}' input.csv> output.csv