Aritra Bhattacharya
Aritra Bhattacharya

Reputation: 780

Leading Zeroes Getting Trimmed while loading data into excel using unix

Leading Zeroes Getting Trimmed while loading data into excel using unix . My platform is MAC. Is there any way we can handle it in Unix without any manual effort.

Thanks

Upvotes: 0

Views: 112

Answers (2)

Walter A
Walter A

Reputation: 19982

Convert numbers into strings with something like

cat inputfile | while read line
   quoteLine=$(echo ${line}|sed 's/,/","/g')
   # do not forget first and last quote, some ugly backslashes here
   echo "\"${quoteLine}\""
done > outputfile.csv

In your case (TAB-separated), you can replace the first , in the sed command by a TAB. Difficult to see when you copy-paste, so you can do it after copying.

Upvotes: 1

Tarik
Tarik

Reputation: 11209

The leading zeroes are removed because as strings containing digits only are converted into numbers. Nothing stops you from changing the format the numbers to show leading zeroes or convert the column to text.

Upvotes: 1

Related Questions