LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 04-26-2016, 02:09 PM   #1
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Rep: Reputation: 15
Create a Csv file


How do i create a Csv file from the list of file in the folder.

Particular folder has lot of pdf files

78945.pdf
12305.pdf

Csv file should look something like this

Column1,Column2
78945.pdf,78945
12305.pdf,12305

Can someone point me in the right direction. I know in Shell i have to use ls command and export it to csv but not sure how to get the second column.

Thanks
 
Old 04-26-2016, 02:20 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
You could do something like this:

Code:
for i in `ls *.pdf`; do echo $i,${i%.pdf}; done > list.csv

Last edited by thesnow; 04-26-2016 at 02:21 PM.
 
1 members found this post helpful.
Old 04-26-2016, 02:28 PM   #3
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Original Poster
Rep: Reputation: 15
Thank you. how do i add the First Line with Column Names ?

Last edited by imkornhulio; 04-26-2016 at 02:33 PM.
 
Old 04-26-2016, 02:34 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by imkornhulio View Post
how do i add the First Line with Column Names ?
Really?? You've been asking about such things since 2008....after EIGHT YEARS, have you not progressed ANY with your skills, and are you not able to apply anything you've been told previously?
http://www.linuxquestions.org/questi...v-file-663835/
http://www.linuxquestions.org/questi...to-tab-683201/
http://www.linuxquestions.org/questi...t-file-699125/
http://www.linuxquestions.org/questi...v-file-898955/
 
3 members found this post helpful.
Old 04-26-2016, 03:19 PM   #5
imkornhulio
Member
 
Registered: Aug 2008
Posts: 58

Original Poster
Rep: Reputation: 15
sed -i '1icolumn1,column2' list.csv found this on web.
 
Old 04-27-2016, 10:37 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Assuming a script, just echo those lines in first. Also, I would not use ls in case of word splitting and use a simple glob (ie. for f in *)
 
Old 04-27-2016, 12:25 PM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by grail
Assuming a script, just echo those lines in first. Also, I would not use ls in case of word splitting and use a simple glob (ie. for f in *)
Yup:
Code:
{ echo 'Column1,Column2'; for i in *.pdf; do echo "$i,${i%.pdf}"; done; } > list.csv
 
  


Reply



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
[SOLVED] A challenging script - Replace field of CSV file based on another CSV file arbex5 Programming 11 06-12-2013 06:56 AM
[SOLVED] where to create csv file frhling Linux - General 1 01-03-2013 09:09 AM
[SOLVED] Need help create a bash script to edit CSV File imkornhulio Programming 13 02-05-2009 10:23 AM
Create 1 csv file from multiple txt files richmur Programming 10 09-03-2008 01:28 PM
create chart from csv file wolfipa Linux - Software 6 01-31-2008 07:59 PM

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

All times are GMT -5. The time now is 02:58 PM.

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