1 |
Hi all, |
2 |
|
3 |
I am trying to do something relatively simple and I've had something |
4 |
working in the past, but my brain just doesn't want to work today. |
5 |
|
6 |
I have a text file with the following (this is just a subset of about |
7 |
2500 dates, and I don't want to edit these all by hand if I can avoid it): |
8 |
|
9 |
--- START --- |
10 |
December 2, 1994 |
11 |
March 27, 1992 |
12 |
June 4, 1994 |
13 |
1993 |
14 |
January 11, 1992 |
15 |
January 3, 1995 |
16 |
|
17 |
|
18 |
March 12, 1993 |
19 |
July 12, 1991 |
20 |
May 17, 1991 |
21 |
August 7, 1992 |
22 |
December 23, 1994 |
23 |
March 27, 1992 |
24 |
March 1995 |
25 |
--- END --- |
26 |
|
27 |
As you can see, there's no standard in the way the date is formatted. |
28 |
Some of them are also formatted YYYY-MM-DD and MM-DD-YYYY. |
29 |
|
30 |
I have a basic grep that I tossed together: |
31 |
|
32 |
grep -o '\([0-9]\{4\}\)' |
33 |
|
34 |
This does extract the year but yields the following: |
35 |
|
36 |
1994 |
37 |
1992 |
38 |
1994 |
39 |
1993 |
40 |
1992 |
41 |
1995 |
42 |
1993 |
43 |
1991 |
44 |
1991 |
45 |
1992 |
46 |
1994 |
47 |
1992 |
48 |
1995 |
49 |
|
50 |
As you can see, the two empty lines are removed but this will cause |
51 |
problems with data not lining up later on. |
52 |
|
53 |
Does anyone have a quick tip for my tired brain to make this work and |
54 |
just output a blank line if there's no match? I swear I did this months |
55 |
ago and had something working but I apparently didn't bother saving the |
56 |
script I made. Argh! |
57 |
|
58 |
Dan |