You are not logged in.
I have a csv like file with numbers and strings separated by comas with lots of lines. I want to change third column (so it is between second and third coma) where are other numbers in each line by numbers from other file were are also different numbers in each lines but there is only one column of numbers.
Is it possible to do it with bash, sed, awk or something else what is able to run in command line?
Last edited by xerxes_ (2022-11-30 23:04:54)
Offline
Use `cut` and `paste`, e.g.,
paste -d, <(cut -d, -f 1-2 first.csv) second.csv <(cut -d, -f 4- first.csv) > new.csv
If you don't mind the column order changing it's even easier (and doesn't require process substitution):
cut -d, -f 1-2,4- first.csv | paste -d, - second.csv > new.csv
(minor edit: s/first,csv/first.csv/)
Last edited by Trilby (2022-12-01 01:44:07)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
No, the column order is important! Your first long command was almost good, but why after third column change the rest of the line is in new line?
UPDATE:
OK, now I know why is that: files were created on windows. Your solution is good. I'll mark it as solved, thanks.
Last edited by xerxes_ (2022-11-30 23:04:16)
Offline
files were created on windows
Pretreat with the popular but totally unnecessary dos2unix, or with a `tr -d '\r'`.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline