Source txt to be imported in xls as .csv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Source txt to be imported in xls as .csv
# 1  
Old 04-12-2011
Source txt to be imported in xls as .csv

Hi ,

I am getting data as below for one of my table as below in a .txt format.I am manually opening a xls sheet, and then selecting import data from option and importing the data in to xls and then saving it as .csv file and this .csv file I am using for one of the shell script.

I am trying to automate the first part that is converting the pipe delimeter data from a .txt file to a .csv file

as I have more than 800 files( in my folder \root\edw\INT\source\) with same .txt extension as to be converted to a .csv files and then use then for my processing.

GEO_ID|GEO_NAME|GEO_PART|GEO_AREA|GEO_REF_NAME|
GEO_PRO_VALUE|GEO_POPULATION|GEO_YEAR|GEO_CROSS_JOIN|
GEO_JOIN2|GEO_MAN_ID|GEO_COUNT|

The above header is from my source file, I need to convert this to a .csv file.

I tried searching in the forum for .txt to .csv files and used some of the commands but I am not getting the required output,is there any option in unix which is similar to import data and select the notepad which we do in xls manually.


Please suggest how can I do this in unix.


Thx,
Shruthi
# 2  
Old 04-12-2011
You're barking up the wrong tree looking for a generic txt to csv converter, because txt isn't generic. What converts some random guy's data probably won't work for yours. Think about the data you have and the data you want, and what needs to change to convert them.

Your data's already CSV file in one sense. It's just text delimited by single characters. That makes it pretty easy

Code:
find /path/to/files -iname '*.txt' | while read FILENAME
do
        tr '|' ',' < "$FILENAME" > "${FILENAME}.csv"
done

should create .txt.csv files in the same folders corresponding to the original files. I don't think carriage returns are needed for excel to open these files.
# 3  
Old 04-12-2011
Hey , can you pls explain what the script is doing , I am working on a similar kind of script.
does the script needs filename as input or will it convert all the .txt files in path to files dir to .csv files.I tried to execute the script it is giving an error as invalid iname

can you explain me the below part
while read FILENAME
do
tr '|' ',' < "$FILENAME" > "${FILENAME}.csv"

Thanks for your time

Regards,
Deepti
# 4  
Old 04-12-2011
Quote:
Originally Posted by gaur.deepti
Hey , can you pls explain what the script is doing , I am working on a similar kind of script.
does the script needs filename as input or will it convert all the .txt files in path to files dir to .csv files.I tried to execute the script it is giving an error as invalid iname
Please show exactly what your script contains.

Quote:
can you explain me the below part
It runs find to find all files named *.txt inside /path/to/files/ and prints them one by one. The while loop reads the names one by one, and for each filename, it reads in from filename, feeds them through tr to replace | with , and sends the output to filename.csv

I think your system must be one that needs -name instead of -iname. Since you hadn't stated your system, I couldn't tell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Csv to xls

Hello I have a script which converts log to csv. Now I need to have xls. Is there any easy way/command which can convert csv to xls?:confused: preferably just using bash and not perl,... is it possible? (1 Reply)
Discussion started by: frhling
1 Replies

2. Shell Programming and Scripting

Oracle to CSV to XLS

I would like to know if have one way with read table from oracle converter in CSV o TXT and After converter in XLS or spreedsheet Thanks so much JAvier (3 Replies)
Discussion started by: javeiregh
3 Replies

3. Shell Programming and Scripting

CSV to XLS

Ok, every morning at my office we send out excel sheets to Economy people with statistics for yesterdays trading. All the trading run's in Redhat or Solaris environments. We run a script on a Redhat server whitch generates the stats in CSV format. After we download we open it in Excel and... (3 Replies)
Discussion started by: chipmunken
3 Replies

4. Shell Programming and Scripting

How to read from txt file and write it to xls?

Hello All, I just want help in coding a simple shell script since i am a newbie for UNIX and i started learning unix and shell scripting basics recently. I am having a data like this in .txt file. Product Name : XYZ Price : 678.1 Best Buy Price : 600 Product Name : ABC Price : 465... (3 Replies)
Discussion started by: vasanth_123
3 Replies

5. Shell Programming and Scripting

how to convert XLS to CSV and DOC/RTF to TXT

Hi, i don't know anything about PERL. Can anyone help me providing PERL scripts for 1. converting XLS to CSV (and vice-versa) 2. converting DOC/RTF to TXT Thanks much Prvn (1 Reply)
Discussion started by: prvnrk
1 Replies

6. Shell Programming and Scripting

converting xls file to txt file and xls to csv

I need to convert an excel file into a text file and an excel file into a CSV file.. any code to do that is appreciated thanks (6 Replies)
Discussion started by: bandar007
6 Replies

7. Shell Programming and Scripting

xls to csv

how to convert a xls file into .csv file? is tghere any command in unix for that? please help thanks (3 Replies)
Discussion started by: infyanurag
3 Replies

8. Shell Programming and Scripting

How to input .txt file into .xls spreadsheet

I need to take the totals from my script and input them into a excel spreadsheet. Right now, I just copy and paste. Is there an easier way? 3906 is the total jobs in ABEND state 4005 is the total jobs in SUCC state 1050 is the total jobs in HOLD state (1 Reply)
Discussion started by: wereyou
1 Replies

9. Shell Programming and Scripting

From xls to csv file

Can we convert an xls file into csv format in Unix Thanks Suresh (1 Reply)
Discussion started by: sureshg_sampat
1 Replies

10. Shell Programming and Scripting

Converting csv to xls

Hi, Can anyone tell the option to change the file type in unix. i.e. if a file is in csv(Comma Separating Values) format, it should be changed to xls(ordinary MS-Excel) format. But renaming command is not changing to correct file format. Thanks in advance, Milton. (1 Reply)
Discussion started by: miltony
1 Replies
Login or Register to Ask a Question