У меня есть огромный список твитов, но я хочу удалить многие из них перед определенной датой. Я думаю, что должен использовать sed, awk, или grep для удаления этих парней, но я не уверен в синтаксисе. Формат для этого находится во втором столбце в форме "18.09.2017 XX:XX:XX", и скажите, что я хотел удалить твиты до 15.09.2017".
Благодарит тонну парни!
Вы могли использовать dategrep
. От perldoc /usr/local/bin/dategrep
:
NAME
dategrep - print lines matching a date range
SYNOPSIS
dategrep --start "12:00" --end "12:15" --format "%b %d %H:%M:%S" syslog
dategrep --end "12:15" --format "%b %d %H:%M:%S" syslog
dategrep --last-minutes 5 --format "%b %d %H:%M:%S" syslog
dategrep --last-minutes 5 --format rsyslog syslog
cat syslog | dategrep --end "12:15"
DESCRIPTION
Do you even remember how often in your life you needed to find lines in a
log file falling in a date range? And how often you build brittle regexs
in grep to match entries spanning over a hour change?
dategrep hopes to solve this problem once and for all.
...
INSTALLATION
It is possible to install this script via perl normal install routines.
perl Makefile.PL && make && make install
Or via CPAN:
cpan App::dategrep
You can also install one of the two prebuild versions, which already
include all or some of dategrep's dependencies. Which to choose mainly
depends on how hard it is for you to install Date::Manip. The small
version is just 22.3KB big and includes all libraries except Date::Manip.
The big one packs everything in a nice, neat package for you, but will
cost you almost 10MB of disk space. Both are always included in the latest
release <https://github.com/mdom/dategrep/releases/latest>.
So, to install the big version you could just type:
wget -O /usr/local/bin/dategrep https://github.com/mdom/dategrep/releases/download/v0.58/dategrep-standalone-big
chmod +x /usr/local/bin/dategrep
And for the small one (with the apt-get for Debian):
apt-get install libdate-manip-perl
wget -O /usr/local/bin/dategrep https://github.com/mdom/dategrep/releases/download/v0.58/dategrep-standalone-small
chmod +x /usr/local/bin/dategrep
Регулярные выражения делают это простой проблемой. Первые выходные даты версии на или после 01.09.2017.
grep -E "2017-([9]|[0-1][0-9])" file > output_file
Этот второй пример дальнейшие фильтры вывод для исключения дат до 15.09.2017. Но только если день месяца является дополненным нулем.
grep -E "2017-([9]|[0-1][0-9])-([0-9]|[0-9][0-9])" file | grep -Ev "2017-9-(0[0-9]|[0-1][0-5])" > output_file
Каждая пара квадратных скобок представляет единственную цифру. |
символьные средства или в regex. См. Руководство Bash для Главы 4 Новичков. Регулярные выражения для получения дальнейшей информации.