Thursday, June 17, 2010

Command/Code to get ASCII value in UNIX

# Character to ASCII
printf "%d\n" "'A"
## ASCII number to character
awk -v char=65 'BEGIN { printf "%c\n", char; exit }'

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

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