1

I am trying to make all values in the 11th column of my .csv file lowercase. I know I can use 'tr A-Z a-z' but how do I make sure it is working in the file I want and only on the 11th column.

1 Answers1

1

It depends what you mean by ".csv file"

In the general case (where quoted CSV fields may contain embedded separator characters, like "foo,bar",baz) you will need to use a tool that can correctly parse that such as one of the Perl / Python / Ruby modules - or Miller.

Ex. given:

$ cat file.csv
ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,ELEVEN,TWELVE

then

$ mlr --csv --implicit-csv-header --headerless-csv-output put '$11 = tolower($11)' file.csv
ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,eleven,TWELVE

For simple comma delimited fields, you could use Awk or even Sed:

$ awk -F, 'BEGIN{OFS=FS} {$11 = tolower($11)} {print}' file.csv
ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,eleven,TWELVE

$ sed -E 's/([^,]+)/\L\1/11' file.csv
ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,eleven,TWELVE
steeldriver
  • 131,985
  • 21
  • 239
  • 326