ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I realized I could print results to a .csv but I wanted to know if I could print results to certain columns and rows I assign. I thought that would be something fun to learn.
I agree with schneidz, it could be easily done with Perl, probably it would be good if you posted an example-file and explain your problem in more detail.
well I thought it would be cool if I echoed items and could place them columns and rows in excel. Not long ago I started learning how to use imagemagick and some its features. I started setting thing as variables and I thought it would be fun to learn how to set each variable in a column and start a new row. I dont really have anything just something I wanted to learn.
Well, I think independent from the language or command you use, the way to put data into a csv-file will always be, to split the line and putting the data into a list. As an example (Perl-code), when the delimiter in the lines is a ";"
Code:
my @data = split /;/, $line ;
afterwards @data (an Array) holds the data of the fields between the ";"
Now one could substitute (or set) the data
Code:
$data[3]="my new data" ;
would put the text "my new data" into the fourth field of the array.
and join the array to a string
Code:
$newline = join /;/, @data ;
There are also solutions possible with sed or awk.
A little off-topic. A csv-file is not the same as an excel-file
Yes, that's true, but Excel can open csv-files and one can also save an Excel-file as csv-file. I don't think that your post is off topic, id could have been mentioned earlier in this thread
thats a good point... ascii (including .csv or .xml) is the most trans-portable format so dealing with .csv (which ms-excel can handle) is easier with trying to translate .xcl files into ascii without a gui.
i remember using a program that would transform open-office odf into ms-excel format (so you can do hundreds at a time) but i forget what it was called.
See, excel has its own proprietary format. So you need specific modules to post your data into excel format and that includes specific rows and columns.
I believe that perl has just such modules. awk as such doesn't have the functionality that you need.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.