Gentoo Archives: gentoo-user

From: Floyd Anderson <f.a@××××.net>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] OT: Extracting year from data, but honour empty lines
Date: Sat, 12 May 2018 02:11:57
Message-Id: 20180512021144.4jrioegyl7swhzaq@31c0.net
In Reply to: [gentoo-user] OT: Extracting year from data, but honour empty lines by Daniel Frey
1 Hi Daniel,
2
3 On Fri, 11 May 2018 16:16:52 -0700
4 Daniel Frey <djqfrey@×××××.com> wrote:
5 >
6 > […]
7 >
8 >Does anyone have a quick tip for my tired brain to make this work and
9 >just output a blank line if there's no match? I swear I did this months
10 >ago and had something working but I apparently didn't bother saving the
11 >script I made. Argh!
12
13 if you can ensure there is only one four-digit year per line, try to
14 strip all other line characters with:
15
16 $ sed -e 's/.*\([0-9]\{4\}\).*/\1/' /path/to/your-date-file
17
18 while keeping none matching lines as they are. Note, pattern is always
19 greedy and picks up the last year it founds.
20
21
22 --
23 Regards,
24 floyd