TAILIEUCHUNG - Linux System Administration phần 10
Trong một kịch bản khác, bạn có thể muốn để lọc các gói tin từ bên trong mạng lưới khu vực địa phương của bạn để ngăn chặn bất cứ ai đến một địa chỉ IP nhất định. Làm thế nào hạn chế tường lửa của bạn phụ thuộc vào các quy tắc bạn thiết lập trong chuỗi IP hoặc bảng IP. | This tool uses C-like language to manipulate structured data one line at a time. awk command files are scripts composed of one or many functional blocks enclosed in curly brackets. Each individual block within the file may be associated with a conditional expression that is used to determine whether that block should be executed upon the current line. As you might guess when there is no conditional expression the block is executed on every line in the file. The very straightforward example awk script shown in Listing takes a file and numbers its lines by a specified increment. Although simple this operation is useful when you are debugging a script or some C source code because syntax-error messages usually include the line number. After the BEGIN keyword the variables are given values. The next block actually prints the number and the line represented by 0. The next line increments the line counter by the specified increment. If there were code that needed to be executed just before the file is closed a block labeled END could be added to the end of the script. Listing A Sample awk Script BEGIN line 1 increment 1 Prints the number and echoes the line. printf 5d s n line 0 line increment To execute this from a file save the code to a file with the extension .awk and issue the following command. The .awk extension is not required but including it clarifies which type of script you are calling. awk -f file newfile Each line matching the conditional expression is prefixed with a line number. If there are no lines matching the conditional expression each line of the file is echoed to the new file and no line numbers are added. Here is another example with the actual actions added to the command instead of in a file ls .zip awk print mv 0 0 .vs bin bash This command will list all files ending in the suffix .zip inputting the list into the awk command. The awk command will use the mv command to rename the files ending in .zip so that they now end in .
đang nạp các trang xem trước