LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2008, 05:29 AM   #1
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Rep: Reputation: 15
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.
 
Old 09-25-2008, 11:08 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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
 
Old 09-25-2008, 11:26 AM   #3
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
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;
If you need only to print a report, not save the value
Code:
print join ',', @lines;

Last edited by Telemachos; 09-25-2008 at 11:28 AM.
 
Old 09-26-2008, 09:34 AM   #4
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Telemachos View Post
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;
If you need only to print a report, not save the value
Code:
print join ',', @lines;
Hello,

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.
 
Old 09-26-2008, 12:25 PM   #5
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Quote:
Originally Posted by dayalan_cse View Post
Hello,

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.
What you have here is a question about Excel or maybe a Notepad question. I can't help because I know nothing about Excel or Notepad. I also don't understand any longer why you called this a Perl question. Good luck.

Last edited by Telemachos; 09-26-2008 at 12:30 PM.
 
Old 09-27-2008, 05:40 AM   #6
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Telemachos View Post
What you have here is a question about Excel or maybe a Notepad question. I can't help because I know nothing about Excel or Notepad. I also don't understand any longer why you called this a Perl question. Good luck.
Hi Telemachos,

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
 
Old 09-27-2008, 06:32 AM   #7
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
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.
 
Old 09-29-2008, 01:25 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,349

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Quote:
multiple lines in a single column.
Quote:
mulitiple rows in a cell
are 2 different things....

What exactly do you want? Give a clear example of before and after.
 
Old 09-29-2008, 01:32 AM   #9
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Give a "real" example of before and after.
 
Old 10-06-2008, 10:13 PM   #10
dayalan_cse
Member
 
Registered: Oct 2006
Posts: 132

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
Give a "real" example of before and after.
Hello All,

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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl object Oriented Programming Question eastsuse Programming 1 08-20-2004 12:29 PM
Hiding code in PERL, perl gui question randomx Programming 1 06-26-2004 03:22 PM
A simple perl programming question J_Szucs Programming 12 07-14-2002 10:03 PM
Perl programming question LindsayJ Programming 0 11-11-2001 02:58 PM
Perl programming AliceC Programming 4 05-17-2001 10:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration