Date post: | 01-Nov-2014 |
Category: |
Technology |
Upload: | anton-arhipov |
View: | 7,672 times |
Download: | 6 times |
Practical *nix utilities(for text processing)
grep | sed | awk | xargs | etc
whoami
/
sed vim
awk
ls
cattac
head
tail split
wc
sumsort
uniqkill
cut
paste
join
tr
dir
mv duecho
test
expr
tee
grep
/
DB
Mega
AppFiles
Log
pwd | ls | find | tee
GNU Coreutilshttp://www.gnu.org/software/coreutils/
The takeaway command: man> info coreutils
pwd | ls | find | teeList of files:
ls –lls –1ls –latr
find . –name *.txt
pwd | ls | find | teeSeek for a string in a file:
grep “cat” file.txtgrep –v “dog” file.txtgrep –i “PaTtErN” file.txtegrep “cat|dog” file.txtzgrep “cat” file.txt.gz
for / xargs
for file in `find . –name *tmp` do rm $file donefind . –name *tmp | xargs rm
Do something with each file:
pwd | ls | find | teefind + grep
find . -name '*txt' -exec grep -l aaa {} \;
find . -name '*txt' | xargs grep -l aaa
pwd | ls | find | tee
ls
cattac
head
tail split
wc
sumsort
uniqkill
cut
paste
join
tr
dir
mv duecho
test
expr
tee
grep
paste
join
sort | uniq
wc
cut
csplit
sed awk
sed s for substitution
sed ‘s/cat/dog/’ # cat -> dog
sed ‘s/\(a\)\(b\)/\2\1/’# ab -> ba
sed p for printing
sed –n ‘/dog/p’ # print lines that match ‘dog’
sed –n ‘/start/,/end/p’# print range
sed d to delete
sed ‘/dog/d’# delete lines that match ‘dog’
sed ‘1,/pattern/d’# delete range
sed | and –e for invocation
sed ‘s/a/A/’ | sed ‘s/b/B/’# sed –e ‘s/a/A/’ –e ‘s/b/B/’ #
sed { .. } to group the commands
sed ‘/pattern/ { s/p/P/ s/e/E/ }’#pattern -> PattErn
sed 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
sedtris
awkaaa bbb cccaaa bbb zzz
awk '/zzz/' 1.txt grep zzz 1.txt
aaa bbb zzz
awkawk 'BEGIN {<initializations>} <pattern 1> {<actions>} <pattern 2> {<actions>} ... END {<final actions>}'
awkawk 'BEGIN {a=0, b=0} /aaa/ {a++} /bbb/ {b++} END {printf “%d\t%d”,a,b}'
awk
awk '{arr[$2]+=$1} END { for (id in arr) printf "%s\t%d\t\n",id,arr[id]}'
exit
@antonarhipov