perl programming question
Hello All,
I want to read the information from one file (in unix) and put it in to csv (comma separated values) i need to use perl for this. I am not sure how multiple lines can be put in to same cell like below. linux questions linux1 questions2 when i tried the multiple lines it shows like below, what i should do to put this information muliple line in a single cell. linuxquestionslinux1questions2 Please let me know if you have any inputs. |
You want concatenate some lines in one variable ? use the ' . ' operator
Or if you want read multiple line in one pass, one way is unset $/ and use s/\n//g |
Two to check out: perldoc -f chomp, perldoc -f join
So, for example if you have the lines chomped and saved in an array, you can easily produce a comma-separated group as easy as Code:
$csv = join ',', @lines; Code:
print join ',', @lines; |
Quote:
thanks for your inputs. my question was how to put muliple lines in single cell, means 1) i opened Microsoft excel sheet 2) i selected a column (cell) 3) i typed as linux and pressed ctrl+enter keys, it goes to the next line in the same cell and i type again linux1 and repeating the ctrl+enter steps 4) i saved this as .csv file when i opened .csv file in notepad it was showing "linuxlinux1" like this string i edited this .csv file in notepad, "computer1computer2" and saved it and i opened in excel but i could not see the string in multiple lines in the single cell. how to do this in .csv file format. |
Quote:
|
Quote:
This is perl question, i wanted to write a script which will put multiple lines in a single column. To be precise in the questions, how can i put mulitiple rows in a cell in .csv file format using perl script. Requirement is below 3 lines show be in single cell one by one line. line1 line2 line3 |
The functions chomp and join should be helpful for solving that problem in Perl, as I said above. I don't know anything about working with Excel spreadsheeets in Perl (or out of Perl), so I'm not sure about the "in one cell" requirement. I would recommend searching on Google for Perl and Excel and on CPAN for Perl modules for Excel.
|
Quote:
Quote:
What exactly do you want? Give a clear example of before and after. |
Give a "real" example of before and after.
|
Quote:
thanks for the information. I found it, to get the multiple lines in single cell in csv file format we need to use \n like below "linux1\nlinux2\nlinux3\nlinux4" if we print the above string in to a file it would display the above string line by line in single cell in spreadsheet. Thanks, Deenadayalan |
All times are GMT -5. The time now is 01:44 PM. |