Replacing first column csv with variable
awk, bash, csv, sed
Solution
This should work:
awk -v dt="$date" 'BEGIN{FS=OFS=","}{$1=dt}1' inputFile
Explaination:
- Use `-v` option to set an `awk` variable and assign it your `shell` variable.
- Set the Input Field Separator and Output Field Separator to `,` (since it is a csv)
- Set the value of `$1` to your `awk` variable.
- `1` is to print the line with modified `$1`.
Problem
I can't believe I couldn't find my question anywhere else in the bash/linux community. I simply want to replace the first column of my csv file with a variable... ``` 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 0,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 2/24/14,8,9,10 ``` I simply just want to replace the first column with `$date`, but all the awk commands don't allow a variable as a the replacement.