User Tools

Site Tools


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

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
команды_фильтры [2018/06/15 14:40]
val [Вывод списка ip адресов из файла]
команды_фильтры [2020/10/06 14:41] (current)
val [tr]
Line 3: Line 3:
 ===== cut ===== ===== cut =====
  
-  * [[http://​ru.wikipedia.org/​wiki/​Cut|cut ​(википедия)]]+  * [[https://​ru.wikipedia.org/​wiki/​Cut|cut ​— команда ​выборки отдельных ​полей из строк файла]]
   * [[http://​unix.stackexchange.com/​questions/​35369/​how-to-cut-by-tab-character|How to cut by tab character]]   * [[http://​unix.stackexchange.com/​questions/​35369/​how-to-cut-by-tab-character|How to cut by tab character]]
  
 <​code>​ <​code>​
-$ cut -d: -f1 /etc/passwd 
 $ cut -d: -f1,7 /etc/passwd $ cut -d: -f1,7 /etc/passwd
-$ cut -d: -f1-3 /etc/passwd+
 $ cut -c1-5 /etc/passwd $ cut -c1-5 /etc/passwd
 +
 +$ cat /etc/passwd | rev | cut -c 2- | rev  #remove last character
 </​code>​ </​code>​
  
 ===== tr ===== ===== tr =====
  
-[[http://​ru.wikipedia.org/​wiki/​Tr]]+  * [[https://​ru.wikipedia.org/​wiki/​Tr|translate или transliterate — Unix-утилита для преобразования символов]] 
 +  * MySQL запросы [[Сервис MySQL#Из командной строки]]
  
 <​code>​ <​code>​
Line 21: Line 23:
  
 $ df -h / | tr -s ' ' $ df -h / | tr -s ' '
 +
 +$ getent group group1 | cut -f4 -d: | tr ","​ "​\n"​
 +
 +$ echo "​{\"​hw_id\":​\"​2\",​\"​hw_name\":​\"​router\"​}"​ | tr -d '​{}\\'​
 </​code>​ </​code>​
  
 ===== sort ===== ===== sort =====
  
-[[http://​ru.wikipedia.org/​wiki/​Sort]]+  * [[https://​ru.wikipedia.org/​wiki/​Sort|sort — UNIX‐утилита,​ выводящая сортированное слияние указанных файлов]]
  
 Ключи -n -r -u -kN Ключи -n -r -u -kN
 +
 +<​code>​
 +$ sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 addresses.txt
 +</​code>​
 +===== uniq =====
 +
 +  * [[https://​ru.wikipedia.org/​wiki/​Uniq|uniq — утилита Unix, с помощью которой можно вывести или отфильтровать повторяющиеся строки]]
 +
 +Cм. пример с grep
  
 ===== grep ===== ===== grep =====
Line 80: Line 95:
  
   * [[https://​stackoverflow.com/​questions/​14928573/​sed-how-to-extract-ip-address-using-sed|sed - How to extract IP address using sed?]]   * [[https://​stackoverflow.com/​questions/​14928573/​sed-how-to-extract-ip-address-using-sed|sed - How to extract IP address using sed?]]
 +  * Генератор отчетов awk [[Генератор отчетов awk#​Выбор строк по числовому условию]]
  
 <​code>​ <​code>​
-# 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+cat /​var/​log/​auth.log | 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])' ​| sort | uniq -c | sort -n
 </​code>​ </​code>​
команды_фильтры.1529062822.txt.gz · Last modified: 2018/06/15 14:40 by val