×
Copy
Open
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
grep | sed | awk | xargs | etc
Slide 2
Slide 2 text
No content
Slide 3
Slide 3 text
sed vim awk ls cat tac head tail split wc sum sort uniq kill cut paste join tr dir mv du echo test expr tee grep
Slide 4
Slide 4 text
DB Mega App Files Log
Slide 5
Slide 5 text
GNU Coreutils http://www.gnu.org/software/coreutils/ The takeaway command: man > info coreutils
Slide 6
Slide 6 text
List of files: ls –l ls –1 ls –latr find . –name *.txt
Slide 7
Slide 7 text
Seek for a string in a file: grep “cat” file.txt grep –v “dog” file.txt grep –i “PaTtErN” file.txt egrep “cat|dog” file.txt zgrep “cat” file.txt.gz
Slide 8
Slide 8 text
for file in `find . –name *tmp` do rm $file done find . –name *tmp | xargs rm Do something with each file:
Slide 9
Slide 9 text
find + grep find . -‐name '*txt' -‐exec grep -‐l aaa {} \; find . -‐name '*txt' | xargs grep -‐l aaa
Slide 10
Slide 10 text
ls cat tac head tail split wc sum sort uniq kill cut paste join tr dir mv du echo test expr tee grep
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
No content
Slide 15
Slide 15 text
No content
Slide 16
Slide 16 text
No content
Slide 17
Slide 17 text
sed awk
Slide 18
Slide 18 text
s for substitution sed ‘s/cat/dog/’ # cat -‐> dog sed ‘s/\(a\)\(b\)/\2\1/’ # ab -‐> ba
Slide 19
Slide 19 text
p for printing sed –n ‘/dog/p’ # print lines that match ‘dog’ sed –n ‘/start/,/end/p’ # print range
Slide 20
Slide 20 text
d to delete sed ‘/dog/d’ # delete lines that match ‘dog’ sed ‘1,/pattern/d’ # delete range
Slide 21
Slide 21 text
| and –e for invocation sed ‘s/a/A/’ | sed ‘s/b/B/’ # sed –e ‘s/a/A/’ –e ‘s/b/B/’ #
Slide 22
Slide 22 text
{ .. } to group the commands sed ‘/pattern/ { s/p/P/ s/e/E/ }’ #pattern -‐> PattErn
Slide 23
Slide 23 text
r to read a file sed ‘/include/ r file.txt’ # insert file.txt after include w to write to a file sed ‘/pattern/ w file.txt’ # write matched lines to a file
Slide 24
Slide 24 text
No content
Slide 25
Slide 25 text
aaa bbb ccc aaa bbb zzz awk '/zzz/' 1.txt grep zzz 1.txt aaa bbb zzz
Slide 26
Slide 26 text
awk 'BEGIN {} {} {} ... END {<final actions>}'
Slide 27
Slide 27 text
awk 'BEGIN {a=0, b=0} /aaa/ {a++} /bbb/ {b++} END {printf “%d\t%d”,a,b}'
Slide 28
Slide 28 text
awk '{arr[$2]+=$1} END { for (id in arr) printf "%s\t%d\t\n",id,arr[id]}'
Slide 29
Slide 29 text
@antonarhipov