[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Change the date format

Posted on 2006-11-29
3
Medium Priority
?
242 Views
Last Modified: 2010-04-20
How can I read a date written in date.data file in the following format:
year/month/day

date.data
-----------
1815/11/02      Boole, George
1864/06/22      Minkowski, Hermann
1854/04/29      Poincare, Jules Henri
1877/09/11      Jeans, James Hopwood
1826/09/17      Riemann, Georg Friedrich Bernhard

and change it to the following format:
George BOOLE (November 2, 1815)

can anyone provide me with the solution.
0
Comment
Question by:saharey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
TraskAdam earned 200 total points
ID: 18035837
A bit of perl ought to do the trick...

[user@localhost /tmp/ee]$ cat data
1815/11/02      Boole, George
1864/06/22      Minkowski, Hermann
1854/04/29      Poincare, Jules Henri
1877/09/11      Jeans, James Hopwood
1826/09/17      Riemann, Georg Friedrich Bernhard
[user@localhost /tmp/ee]$ cat conv.pl
#!/usr/bin/perl -n

@mon = ("",
        "January",
        "March",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
);
next unless (\/^(\d+)\/(\d+)\/(\d+)\s+([^,]+),\s*(.*)$/);

$year = $1; $mon = $2; $day = $3;
$last = $4; $first = $5;

printf "%s %s (%s %d, %d)\n",
        $first, uc($last), $mon[$mon], $day, $year;

[user@localhost /tmp/ee]$ cat data | ./conv.pl
George BOOLE (November 2, 1815)
Hermann MINKOWSKI (June 22, 1864)
Jules Henri POINCARE (April 29, 1854)
James Hopwood JEANS (September 11, 1877)
Georg Friedrich Bernhard RIEMANN (September 17, 1826)
[user@localhost /tmp/ee]$

... prolly a programatic way to find the name of the month using strftime() instead of a predefined array but it doens't seem worth the effort here.  Should probably also report bogus lines istead of just ignoring them so...

next unless (\/^(\d+)\/(\d+)\/(\d+)\s+([^,]+),\s*(.*)$/);

... should be more like...

unless (\/^(\d+)\/(\d+)\/(\d+)\s+([^,]+),\s*(.*)$/) {
       print STDERR "unrecongised line: $_";
       next;
}
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question