1

it easy on Linux to create CSV file as:

   echo names,OBAMA,PUTIN,KAMERUN > NAMES.csv

it will create CSV file ( sheet 1 )

but is it possible to create second or third or more sheets in the CSV file?

for example ( I want to create now second sheet - sheet 2 )

   echo best_air_force,USA,RUSSIA,ENGLAND > NAMES.csv

remark - I use bash scripts on my linux machine

1
  • You could consider to have a directory named FILE.csv and having inside this directory different files from different data sources and with different names... You may think of a better extension for the container directory and could even devise a CLI interface to operate on the data in the different sheets, placing the result in a different place. By repeating indexes in different tables you can ... strange dejavù feeling , I'll stop here for now. Ciao from Commented Nov 2, 2014 at 14:18

2 Answers 2

7

You can't. The CSV file format doesn't provide support for multiple sheets.

Sign up to request clarification or add additional context in comments.

Comments

2

The answer depends on what tool you are going to use to display/edit the file as separate sheets. For example, you could create a CSV file like:

a,b,c
-
d,e,f

and then you can use a script like this (GNU awk for multi-char RS):

awk -v sheet=<number> -v RS='(^|\n)-\n|\n$' 'NR==sheet' file

to select sheets:

$ awk -v sheet=1 -v RS='(^|\n)-\n|\n$' 'NR==sheet' file
a,b,c
$ awk -v sheet=2 -v RS='(^|\n)-\n|\n$' 'NR==sheet' file
d,e,f

Since there is no one spec for "CSV" you could still say this is "CSV" but in this case I'd name the tool you use to view it as separate sheets something like "foo" and use ".foo" instead of "csv" as the suffix. Like MS does with "Excel" and ".xls".

You can use any sequence of characters you like with as many fields as you liek to indicate the sheet-separator, e.g.:

-,-,-

<control-char>,<control-char>,<control-char>
END OF SHEET

That second one above is a blank line. The point is the separation into sheets only makes sense in the context of whatever tool you use to display/edit those sheets and you are in complete control of what the separator is since you'll be writing the tool that uses it. It just has to be some string that you know cannot appear naturally in the rest of your file.

9 Comments

Er… while I suppose you can technically do this, standard spreadsheet applications (like Excel) won't recognize it.
There is no standard and therefore there are no standard CSV applications. If you want a file that Excel can open to display multiple sheets, that's a different question with the same answer - you need to use whatever convention the tool you are planning to open it with uses to indicate different sheets. If Excel doesn't have a convention to separate sheets in a CSV file then obviously you can't use Excel to open a CSV file containing multiple sheets but that absolutely does not mean you can't have a CSV file that contains multiple sheets - you just have to use the right tool to open it.
Have you glanced at the contents of that document? The first paragraph specifically says "This memo ... does not specify an Internet standard of any kind." and then goes on to discuss some of the different possible formats of CSV file and gives specific references to 4 of the documents that define them. There are several documents that define some kind of format for CSV files, almost always in the context of the tool provided by the organization that wrote the document, but there is no standard.
Right, that's because the term "Internet standard" has a very specific meaning in the RFC process. It's used sparingly, typically for really important specifications like TCP. There are currently 79 Internet standards.
CSV, as specified in RFC 4180, is a "standard" because it's a well-defined format recognized and supported by a wide variety of applications. The extensions you're proposing in this post fall outside that standard, in that it will not be parsed in the expected way (if at all) by any of these applications. It could be a useful format in its own right, but calling it "CSV" is incorrect.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.