[Thread Prev][Thread Next][Index]

Re: [ferret_users] Reading ASCII data including formatted dates



Ferret users,

On Tue, Mar 20, 2018 at 8:07 AM, William S. Kessler <william.s.kessler@xxxxxxxx> wrote:
[ . . . ]
I finally kluged this by editing the text

I'd like to add something that might be useful to somebody in the future.  I sometimes have to edit text files to use as input to Ferret or other tools and do these things a lot.  In this particular case, we want convert "05-Sep-2007" to "05/09/2007".  Using the GNU version of the date command, this is how you do that:

date --date="05-Sep-2007" +"%d/%m/%Y"

(On Mac, you can install it by "brew install coreutils" and the name of the command will be "gdate" instead of "date".)  The 3rd parameter looks scary but it's nothing but a format string like Fortran's "F10.3", etc.

The next piece is to read lines from the text file, modify it, and write the result to a new file:

cat inputfile.txt | while read col1 col2 rest; do
    newdate=$(date --date="$col2" +"%d/%m/%Y")
    echo $col1 $newdate $rest
[ferret_users] Reading ASCII data including formatted dates
  • From: William S. Kessler
[Thread Prev][Thread Next][Index]