awk中的'数组'

awk中的’数组‘是一种关联数组,又称作maps、字典,他的索引不需要连续, 可以使用字符串、数字做为索引, 此外,不需要事先声明数组的大小 - 数组可以在运行时扩展/收缩。 语法: 赋值: 1 array_name[index] = value 删除: 1 delete array_name[index] 多维数组(使用字符串模拟) 1 array["0,0"] = 100 遍历: 1 2 for (var in arrayname) actions 实例 统计汇总 数据:Iplogs.txt 1 2 3 4 5 6 7 8 180607 093423 123.12.23.122 133 180607 121234 125.25.45.221 153 190607 084849 202.178.23.4 44 190607 084859 164.78.22.64 12 200607 012312 202.188.3.2 13 210607 084849 202.178.23.4 34 210607 121435 202.178.23.4 32 210607 132423 202.188.3.2 167 total.awk: 1 2 3 4 5 6 7 { Ip[$3]++; } END { for (var in Ip) print var, "access", Ip[var]," times" } 注意下END后的{需要和END在一行 输出: 1 2 3 4 5 6 $ awk -f total.awk Iplogs.txt 123.12.23.122 access 1 times 164.78.22.64 access 1 times 202.188.3.2 access 2 times 125.25.45.221 access 1 times 202.178.23.4 access 3 times 说明: $3是一个IP地址, Ip做为数组的索引。 对于每一行,它会增加相应IP地址索引的值。 最后在END部分中,所有索引都将是唯一IP地址的列表,其对应的值是出现次数。 ...

2019-08-31 · 4 min · 728 words · Garlic Space

FTP ASCII上传下载

近期在进行AIX到Linux迁移,发现从windows终端ftp时,客户端设置ASCII传输模式, 服务端并不能自动转换换行符号,脚本出现^M,需要手工删除。 Linux环境为RedHat7.3+vsftpd3.0.2,vsftpd.conf中ascii_download_enable/ascii_upload_enable 注释

2019-08-31 · 3 min · 573 words · Garlic Space

LeetCode – Binary Tree Inorder Traversal

题目: Given a binary tree, return the inorder traversal of its nodes\’ values. Example: Input: 1 2 3 4 5 6 [1,null,2,3] 1 \ 2 / 3 Output: 1 [1,3,2] Follow up: Recursive solution is trivial, could you do it iteratively? 解题: 树的中序遍历: 如果当前节点的左孩子为空,则输出当前节点并将其右孩子作为当前节点。 如果当前节点的左孩子不为空,在当前节点的左子树中找到当前节点在中序遍历下的前驱节点。 a) 如果前驱节点的右孩子为空,将它的右孩子设置为当前节点。当前节点更新为当前节点的左孩子。 b) 如果前驱节点的右孩子为当前节点,将它的右孩子重新设为空(恢复树的形状)。输出当前节点。当前节点更新为当前节点的右孩子。 重复以上1、2直到当前节点为空。 实现: 递归方式: 对左子结点调用递归函数,根节点访问值,右子节点再调用递归函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<int> inorderTraversal(TreeNode* root) { vector <int> res; inorder(root, res); return res; } void inorder(TreeNode *root, vector<int> &res){ if (!root) { return; } if (root->left) { inorder(root->left, res); } res.push_back(root->val); if (root->right){ inorder(root->right, res); } } }; 空间复杂度:O(n), 时间复杂度:O(n)。 使用栈实现 从根节点开始,先将根节点压入栈,然后再将其所有左子结点压入栈,然后取出栈顶节点,保存节点值,再将当前指针移到其右子节点上,若存在右子节点,则在下次循环时又可将其所有左子结点压入栈中。这样就保证了访问顺序为左-根-右, ...

2019-08-31 · 2 min · 225 words · Garlic Space

linux kernel documentation-CFS Scheduler

这篇文章 CFS Scheduler是Linux Kernel文档

2019-08-29 · 2 min · 244 words · Garlic Space

LeetCode – Target Sum

题目: You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol. Find out how many ways to assign symbols to make sum of integers equal to target S. Example 1: 1 2 3 4 5 6 7 8 9 10 11 Input: nums is [1, 1, 1, 1, 1], S is 3. Output: 5 Explanation: -1+1+1+1+1 = 3 +1-1+1+1+1 = 3 +1+1-1+1+1 = 3 +1+1+1-1+1 = 3 +1+1+1+1-1 = 3 There are 5 ways to assign symbols to make the sum of nums be target 3. Note: ...

2019-08-20 · 3 min · 441 words · Garlic Space

LeetCode – Clone Graph

Given a reference of a node in a connected Connected_graph undirected graph, return a deep copy

2019-08-09 · 2 min · 426 words · Garlic Space

linux-sides-Timers and time management-Introduction

这篇文章 Timers and time management in the Linux kernel. Part 1. 是出自 linux-insides

2019-08-07 · 4 min · 796 words · Garlic Space

sysctl-查询修改Linux内核参数

sysctl命令可以_实时_(runtime)查看和修改linux 内核参数。这个命令可以在大多数发行版本找到, 另外内核参数,也可以通过procfs 文件系统,在 /proc/sys/kernel下 进行查看和修改。

2019-08-06 · 2 min · 219 words · Garlic Space

LeetCode – Evaluate Reverse Polish Notation

题目: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Note: Division between two integers should truncate toward zero. The given RPN expression is always valid. That means the expression would always evaluate to a result and there won’t be any divide by zero operation. Example 1: Input: 1 ["2", "1", "+", "3", "*"] Output: ...

2019-08-04 · 2 min · 417 words · Garlic Space

汇编文件中的CFI指令

这篇文章CFI directives in assembly file (18 Jan 2017), 是出自google 工程师Adam Langley 问题提出: 函数调用栈 1 2 3 4 5 6 7 8 : : | caller's stack | +----------------+ <----$rsp value before CALL | return address | +----------------+ <----$rsp at function entry | caller's rbp | +----------------+ <----$rbp always points here | callee's stack | 函数调用中 调用call指令时将call指令的下一条指令 return address 入栈, 其中return address存放在RIP寄存器中也就是将 RIP入栈,之后进入子函数后会将父函数的栈基地址入栈,其中父函数的栈基地保存在RBP寄存器中。 函数栈调用框架: push rbp mov rbp, rsp ...

2019-07-09 · 2 min · 248 words · Garlic Space