I was trying to change the file name from gdf to csv in the folder using

$for i in *.dbf; do mv $i ${i%.dbf}.ods; done script.

The code changed all the gdf to csv, but the content of the new files is diffenet from the orginal gdf file.

Here are the sample files below. The file has two columns.


time,N,19,11    prec,N,13,11
19710101.00000000000    0.02072840000
19710102.00000000000    0.42218300000
19710103.00000000000    0.17756100000
19710104.00000000000    0.33698200000
19710105.00000000000    0.11057700000
19710106.00000000000    0.02841580000
19710107.00000000000    0.00000000000
19710108.00000000000    0.00000000000
19710109.00000000000    0.00000000000

the result from above code is 1_CopyRow.ods

  • rma!WtimeFprecF

    1.97101010000e+007 2.07284e-002 1.97101020000e+007 4.22183e-001 1.97101030000e+007 1.77561e-001 1.97101040000e+007 3.36982e-001 1.97101050000e+007 1.10577e-001 1.97101060000e+007

I want the output be file be the same as the input. I couldn't figure out how to fix the problem. Any suggestions?

  • 1
    cannot possibly happen from the mv command. How are you opening these files? – glenn jackman Aug 29 '14 at 20:05
  • They are ArcGIS table outputs. I opened them using excel import – AiB Aug 29 '14 at 20:30

The files are the same. If you open a terminal and type cat 1_CopyRow.dbf followed by cat 1_CopyRow.ods then you'll notice that they are the same.

What's happening is that Open/Libre Office (I presume you're opening the .ods file using this) is formatting the file for display.

1.97101010000e+007 = 1.9710101 x 10^7 = 19710101 = 19710101.000000000

That is, they are all the same value.

Note that your question is unclear as to whether you're renaming to .ods or .csv.

  • Thank you for your prompt answer. They look the same from the terminal. But when I open them with excel, they are different. The dbf is table output form ArcGIS. It has two columns only. When I open the .ods/csv file after changing the name, they are arranged all in one row. I have a couple of these file to join all in one file for my model input. It can ce changed either to .ods or .txt or .csv. – AiB Aug 29 '14 at 20:23
  • 2
    Ah! I see what you're asking now. A CSV file expects commas between fields (hence the name - Comma Separated Values) but your data doesn't have this. I believe Excel has an option to import from text files and gives you the option to choose the field delimiter. If the large space between the columns is a tab, then choose 'tab' when you import. – garethTheRed Aug 29 '14 at 20:35
  • @garethTheRed as a side note, I always liked using diff <file one> <file two> > delta.txt. diff is very useful in situations like this, especially if num_of_lines >> 10 :-) – Simply_Me Aug 29 '14 at 22:01
  • @Simply_Me I did consider diff but (on Ubuntu & Fedora at least) it needs the diffutils package installed - I assumed cat would be on all systems. Also, if I was wrong, diff would have spewed out some scary looking results! – garethTheRed Aug 30 '14 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.