Search This Blog

Friday, March 12, 2010

In a directory in Unix convert Tab Delimeted file to Comma delimeted

On Request from one of our reader here is a post to convert excel files into a comma delimeted file.

create shell script using following code. The script below will fetch all files with extension xls and convert tabs into comma and create a .csv file.

cd /applmgr/custom/inbound/data
for i in *.xls
echo $i
awk 'BEGIN {
FS = "\t"
OFS = ","
$1 = $1
for (i = 1; i <= NF; i++) {
if ($i == "") {
$i = "null"
print $0
}' $i > $newfile

1 Comment:

Anonymous said...

Very Nice

Copyright (c) All rights reserved. Presented by Suresh Vaishya