Hi
i want to convert a tab separated file into csv file
can anyone help me
Hi
i want to convert a tab separated file into csv file
can anyone help me
Try replacing all the tabs with commas.
Possibly with a regex like s/\t/,/g
, if you don't have any quoted fields.
Or, you know, Excel could do that for ya. Or R. Or anything which can take in a TSV file.
You can use sed as:
sed 's/\t/,/g' input_file > output_file
This will keep the input file unchanged and will create a new file output_file
with the changes.
If you want to change the input file itself without creating a new file you can use -i
option to sed to do inplace changes:
sed -i 's/\t/,/g' input_file
Is this the usual easy-question-all-languages thing? Okay, here is my haskell solution:
main = interact (unlines . replTab . lines) where
replTab l = l >>= (\line ->
"\"" ++ line "\"" >>= \char ->
case char of
'\t' -> "\",\""
'"' -> "\"\""
_ -> [char]
)
not tested, but should work.
PS: All the other solutions aren't aware of escaping commas.