CSV file | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

CSV file

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-29-2011
GRS64 GRS64 is offline
Registered User
 
Join Date: Jan 2011
Last Activity: 3 February 2011, 3:55 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
CSV file

I am new to script writing. With the help of others I now have a script that reads the files names in a folder and records each file name in a comma delimited file. "import.txt".

I can now import this into Open office Calc as a TextCSV file but it places each file name at the head of a separate column.

What I really want is to be able to import the file such that it shows each file name in a separate row but in the 1 column.

It seems to me I need some how to put a return. line feed or carriage return in where the , is in the script.

How do I do this?


I known one can do an Edit cut and the a special paste in a way that transposes the data base from a single long row of data and to a single column but this is messy for the numbers I have to do. So if it can be done in the generation of the CSV file it would be a lot beter and easier.

I am using OpenOffice 3.3, and Fedora 14 64 bit as the OS

The current script in the area where the comma is is

"$LINE," >> import.txt: done.

This works fine for what I want but it gives the end results as I say with the file name one per column when importing as comma delimited.

Thanks
Sponsored Links
    #2  
Old 01-29-2011
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 25 November 2014, 4:08 AM EST
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
Reverse the process :

fill up filenames in a column in an Open Office file
save it as csv
transfer in binary to your unix machine, and edit the file with

Code:
vi yourfile.csv

press <Esc> key to make sure you are in command mode
then
:se list
this will make vi display <tab> or "\r" keys into readable caracter ^I ^M

You will then be able to see what character you need to add into the file you want to generate so you can make it fit the Open Office csv format.

to exit vi, just use the following seqence (still in command mode)
:q!
Sponsored Links
    #3  
Old 02-03-2011
GRS64 GRS64 is offline
Registered User
 
Join Date: Jan 2011
Last Activity: 3 February 2011, 3:55 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the reply. I generated a file as you suggested and looked at the readable character it put in to the TextCSV file the showed up as "bread"$ where the $ was coloured blue. There was a $ characters after every line so when I tried in import it again I have all the names listed in a single column with each on a different row.


So I tried to change the text file I had generated with the files names in it. The $ was just put in as a $ straight from the key board (just in black) but when the text files was imported using TextCSV into open office all the file names were in one row and one column.

Clearly the $ was not being recognised as a control character.

Do not quite know where to go from here
    #4  
Old 02-03-2011
rajesh_pola rajesh_pola is offline
Registered User
 
Join Date: Oct 2010
Last Activity: 7 February 2012, 11:41 AM EST
Posts: 47
Thanks: 0
Thanked 4 Times in 4 Posts
if you don't mind can i give a simple solution for that..


take tha file name as a variable and add it to the file it self as first column or last column and print the file.

then it will give your our put.

you try it..
or else i wil give the code..

regards
rajesh
Sponsored Links
    #5  
Old 02-03-2011
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 25 November 2014, 4:08 AM EST
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
Quote:
Originally Posted by GRS64 View Post
Thanks for the reply. I generated a file as you suggested and looked at the readable character it put in to the TextCSV file the showed up as "bread"$ where the $ was coloured blue. There was a $ characters after every line so when I tried in import it again I have all the names listed in a single column with each on a different row.


So I tried to change the text file I had generated with the files names in it. The $ was just put in as a $ straight from the key board (just in black) but when the text files was imported using TextCSV into open office all the file names were in one row and one column.

Clearly the $ was not being recognised as a control character.

Do not quite know where to go from here
The $ you see just means "end of line" so you don't need to add these.
to go back to display in a normal way use :

:se nolist (still in vi command mode)

You must just make sure that the file you want to generate with your script look like the one you have edited with vi.

1) Could you please provide your all code ?

maybe try something like:

Code:
echo "$LINE," >> import.txt

2) or :


Code:
cd folder
ls -1 | sed 's/$/,/' >>import.txt


Last edited by ctsgnb; 02-03-2011 at 07:20 PM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Before I delete any file in Unix, How can I check no open file handle is pointing to that file? kchinnam Solaris 12 10-06-2010 03:30 PM
file size comparision local file and remote file dba.admin2008 Shell Programming and Scripting 4 11-13-2008 05:57 PM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 05:25 AM



All times are GMT -4. The time now is 07:10 AM.