Issue
i have a line as below and all fields separated by comma:
I want to replace 2nd filed which is 11:50:21.444 with a value stored in variable "b"
01-01-2022,11:50:21.444,1234543233443,0,0,0,0,1
I tried using sed cat abc.csv| sed 's/$2/$b/'
Solution
Any time you find yourself talking about fields you should use awk rather than sed or grep since awk has a concept of fields while the others don't and awk can do literal string replacements while sed can't.
awk -v b="$b" 'BEGIN{FS=OFS=","} {$2=b; print}' abc.csv
Answered By - Ed Morton Answer Checked By - Mary Flores (WPSolving Volunteer)