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

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

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.

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

Please show exactly what your script contains.

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.