User Tools

Site Tools


команды_фильтры

This is an old revision of the document!


Команды фильтры

cut

$ cut -d: -f1 /etc/passwd
$ cut -d: -f1,7 /etc/passwd
$ cut -d: -f1-3 /etc/passwd
$ cut -c1-5 /etc/passwd

tr

sort

uniq

grep

http://ru.wikipedia.org/wiki/Grep

$ grep root /etc/passwd

$ grep -i Root /etc/passwd

$ grep '^root' /etc/passwd

$ grep 'sh$' /etc/passwd

Ключ -r - рекурсивный перебор подкаталогов

$ grep -r '\<sed\>' /usr/share

Ключ -v - показать строки, не совпадающие с шаблоном

FreeBSD
/usr/local/etc/apache/httpd.conf

Linux
/etc/apache2/apache2.conf
/etc/apache2/sites-available/default-ssl
$ grep -v '^#' file
$ grep -v '^ *#' file
$ grep -v '^ *#\|^$' file
$ grep "^[^#]" /etc/ssh/sshd_config

Ключ -E - использовать расширенные регулярные выражения

$ grep -vE '^ *#|^$' file

Примеры использования

Статистика посещений за день

# fgrep '05/Dec/2011' /opt/local/apache2/logs/access_log | cut -f1 -d' ' | sort -u | wc -l

Вывод списка ip адресов из файла

# grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' /var/log/auth.log | sort | uniq -c | sort -n
команды_фильтры.1531205407.txt.gz · Last modified: 2018/07/10 09:50 by val