|
Introduction
Operation and maintenance should always do with these two tools sed and awk, but to put them to good use is no easy task, it takes a long time to accumulate, rough paper used in everyday talk about some examples.
text
1 How to get the string string in shell length
echo $ {# string}
2 Replace text file in one or more spaces
sed -i "s / \ + / || / g" test
NOTE: \ + means that one or more of the previous character
3 Delete the text in the file "[" and "]" two characters
sed -i -e "s / \ [// g" -e "s / \] // g" text
Each column of text 4 text separated by commas, and now you want to delete the sixth column, then the output of the other columns, each separated by a space
awk 'BEGIN {FS = ","; OFS = ""} {$ 6 = ""; print $ 0}'
CPU 5 percent output for each user occupied
top -bn 1 | awk '{if (NR> 7) print $ 0}' | awk '{sum [$ 2] + = $ 9} END {for (i in sum) printf "% .2f% s \ n", sum [i], i} '| sort -nr
6 Statistics nginx's access.log each url access number and the flow output of the previous 10
awk '{print $ 7 "\ t" $ 10}' access_2010-12-8.log | awk '{S [$ 1] + = $ 2; S1 [$ 1] + = 1} END {for (i in S) print S [ i], S1 [i], i} '| sort -rn | head -10 |
|
|
|