generate a csv file
44,677
There is nothing magical about a .csv file. It just means comma (occasionally tab) separated values.
mv myfile.txt myfile.csv
done
Related videos on Youtube
Author by
pinkpostit
Updated on September 18, 2022Comments
-
pinkpostit almost 2 years
I have a script that generates a
.txt
file.That file have
tab-delimited
columns. The number of columns vary depending on the input file.How can I convert that
.txt
file to csv format? I want to have the columns in the.txt
file be in separate columns in the csv file.sample:
.txt
file:header1 header2 header3 header4 1 B 423.sagd.32 333 2 A YXTS.a324.gfd33 555 3 F 343.asr 222 4 D cbs.98st.asd 4232
CSV file (expected output):
A B C D 1 header1 header2 header3 header4 2 1 B 423.sagd.32 333 3 2 A YXTS.a324.gfd33 555 4 3 F 343.asr 222 5 4 D cbs.98st.asd 4232
Note: The file do not have a fixed number of columns or rows.
-
phk over 7 yearsWhat do you mean with expected output if that's not clearly not a CSV?
-
AlexP over 7 yearsCSV means Comma-Separated Values. The exemplified output is not a CSV file.
-
-
pinkpostit over 7 yearsI tried that but when I look at the csv file, all the columns in the .txt file are all in column A when I open the csv file in excel.
-
sam over 7 yearsAre you using spaces or tabs?
-
pinkpostit over 7 yearsi am using tabs
-
sam over 7 yearsHmm... this seems to be specific to how Excel is choosing to import the data. Im sure you can set the defaults somewhere. I just tried it out and if you import the csv it will delimit properly, but opening it doesn't seem to. This is an excel setting however and not linux related. Just as a side note, LibreOffice Calc seems to parse the delimiters correctly every time for me.