- 浏览: 198615 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (391)
- java (18)
- python (3)
- ruby (4)
- linux (48)
- 网络 (9)
- 前端 (2)
- 社会、文化、哲学、人生、百态 (0)
- 工具 (10)
- 下载 (0)
- 常用地址 (0)
- tracert (0)
- mysql (8)
- 开源相关收藏 (1)
- 模块查看依懒 (1)
- watch使用 (1)
- Tcpdump (2)
- easy_install安装 (1)
- 构造redis批量删除脚本 (1)
- MYSQL 性能测试 (1)
- JAVA code encode utf-8 (1)
- linux nginx awk 实时 每妙 (1)
- mkpasswd (1)
- spring security oauth (1)
- jmap dump java memory Analyzer (1)
- JAVA DUMP (1)
- swap linux 过高 解决 (1)
- SWAP (1)
- jmap jstat jstack dump (1)
- java jconsole 的使用 (1)
- git 常用 (1)
- MYSQL 索引 动态 唯一 (1)
- TCP 三次握手 四次挥手 (1)
- linux date (1)
- 删除 空行 注释行 (1)
- maven3 yum linux install repository (1)
- linux git 搭建 (1)
- linux sar eth1 查看 流量 (1)
- sar (1)
- netstat ip 过滤 常用脚本 (1)
- Tcpdump 包分析网络连接过程 (1)
- net ipv4 tcp time wait tw recycle (0)
- /etc/sysctl.conf linux 网络 配置 (1)
- ss 网络连接查看 (比netstat 快很多,实时性牺牲) (1)
- MYSQL 关键字 (1)
- Linux 下多核CPU知识 (1)
- top (1)
- 令牌 证书 (1)
- mysql unix timestamp (1)
- 端口扫描 nc nmap (1)
- 204 http code 状态码 (1)
- ss -s ss -l (1)
- linux 常用 curl (1)
- linux sed 替换 换行 (1)
- centos yum install rpm install (1)
- spring-mvc源码解读 (1)
- 使用iftop查看实时的网络流量 (0)
- linux 命令 expect (1)
- HTTP (1)
- openssl ddif 加密 (1)
- iptables 详解 (1)
- python 虚拟化 VirtualEnv virtualenvwrapper (1)
- nginx (2)
- more less 实用技巧 (1)
- linux nginx (2)
- linux curl https ssl 证书 ca (1)
- openssl (1)
- php mysql linux (1)
- linux 虚拟机 虚拟 xen (0)
- linux 虚拟机 虚拟 xen kvm (1)
- linux perl 单行执行技巧 (1)
- mysql 查看库占用空间 表查用空间 (1)
- linux tcpdump (1)
- maven (1)
- sun.misc.Unsafe (1)
- OpenSSL生成证书 (1)
- http://blog.csdn.net/zzulp/article/details/8018751 (1)
- maven 本地 jar dependency (1)
- 计算JAVA代码行数最简单命令 sed (1)
- 常用的证书格式转换 rsa eg (1)
- 加密 解密 签名 (1)
- 分析jar包冲突 (1)
- 使用JMockit编写java单元测试 (1)
- Linux 技巧:让进程在后台可靠运行的几种方法 (1)
- 环境变量控制 (1)
- 5+ 个 tar 命令的用法,附示例 (1)
- scp自动输入密码 (1)
- ps axo pid (1)
- ppid (1)
- comm (1)
- pmem (1)
- lstart|grep mysql (0)
- lstart (1)
- etime|grep mysql (1)
- UML类图字少好理解 (1)
- HTTP经典文章 (1)
- git (1)
- Git常用命令 (1)
- LINUX 系统被攻击的分析过程 (1)
- NIO (1)
- LINUX 操作快捷键使用 (1)
- openSSL命令、PKI、CA、SSL证书原理 (1)
- shell (2)
- 转载 (1)
- mysqldump 可以直接dump->xml (1)
- VIM比较全面的文章 (1)
- eclipse regex 正则表达式 (1)
- synchronized (1)
- 锁 (1)
- java 正则表达式 regex (1)
- Reference Queue 引用 源码 (1)
- spring aop 源码 分析 (1)
- java @Cache @Transaction 注解 (1)
- spring aop (1)
- spring jdk proxy cglib 动态代理 性能比较 (1)
- spring proxy private public 代理限制 (1)
- spring transaction aop 事务 (1)
- spring autowire 注解注入 (1)
- 桥接 NAT NAT地址转换 内部网络 虚拟网络 (1)
- spring-web-mvc 源码解读 之 RequestMappingHandlerMapping (1)
- find atime mtime ctime -n n +n (1)
- android studio 快捷键初探 (1)
- android 源码阅读的计划 (1)
- 计算机网络学习-VLAN (1)
- sed 高级 合并行 (1)
- CAP 一致性 可用性 分布式容错性 (1)
- android lib so 库文件 (0)
- android lib so 库文件 移植 (1)
- android 不错的博文 (1)
- sourceinsight 源码 阅读 (1)
- Android Tab UI (1)
- 诗 (1)
- mysql 批处理 (0)
- netty 堆外内存 DirectByteBuffer (1)
- netty 并发 百万 推送 (1)
- Linux操作系统中内存buffer和cache的区别 (1)
- maven intellij target bytecode version (1)
- linux sleep()的实现原理 (1)
- android (2)
- javadoc 代码注释规范 (1)
- spring 自动注入bean auto (1)
- Photoshop CS6常用快捷键 (1)
- 股票 数据 机器 分析 (1)
- 批处理 (1)
- mysql -e (1)
- char (1)
- Unicode (1)
- 编码 (1)
- utf8 (1)
- utf-8 (1)
- utf16 (1)
- utf-16 (1)
- IntelliJ IDEA (1)
- ide (1)
- idea (1)
- intellij (1)
- 文件 (1)
- 目录 (1)
- 源代码 (1)
- CountDownLatch (1)
- CyclicBarrier (1)
- Semaphore (1)
- spring (1)
- linux 查看不同进制文件 (1)
- WebMvcConfigurationSupport (1)
- sdkman工具的使用 (1)
- http header (1)
- LINUX系统优化 (1)
最新评论
-
gelongmei:
威武我大酒神
shell脚本不换行刷新数据
gsub(regexp, replacement [, target])
Search target for all of the longest, leftmost, nonoverlapping matching substrings it can find and replace them with replacement. The ‘g’ in gsub() stands for “global,” which means replace everywhere. For example:
{ gsub(/Britain/, "United Kingdom"); print }
replaces all occurrences of the string ‘Britain’ with ‘United Kingdom’ for all input records.
The gsub() function returns the number of substitutions made. If the variable to search and alter (target) is omitted, then the entire input record ($0) is used. As in sub(), the characters ‘&’ and ‘\’ are special, and the third argument must be assignable.
index(in, find)
Search the string in for the first occurrence of the string find, and return the position in characters where that occurrence begins in the string in. Consider the following example:
$ awk 'BEGIN { print index("peanut", "an") }'
-| 3
If find is not found, index() returns zero. (Remember that string indices in awk start at one.)
length([string])
Return the number of characters in string. If string is a number, the length of the digit string representing that number is returned. For example, length("abcde") is five. By contrast, length(15 * 35) works out to three. In this example, 15 * 35 = 525, and 525 is then converted to the string "525", which has three characters.
If no argument is supplied, length() returns the length of $0.
NOTE: In older versions of awk, the length() function could be called without any parentheses. Doing so is considered poor practice, although the 2008 POSIX standard explicitly allows it, to support historical practice. For programs to be maximally portable, always supply the parentheses.
If length() is called with a variable that has not been used, gawk forces the variable to be a scalar. Other implementations of awk leave the variable without a type. (d.c.) Consider:
$ gawk 'BEGIN { print length(x) ; x[1] = 1 }'
-| 0
error--> gawk: fatal: attempt to use scalar `x' as array
$ nawk 'BEGIN { print length(x) ; x[1] = 1 }'
-| 0
If --lint has been specified on the command line, gawk issues a warning about this.
With gawk and several other awk implementations, when given an array argument, the length() function returns the number of elements in the array. (c.e.) This is less useful than it might seem at first, as the array is not guaranteed to be indexed from one to the number of elements in it. If --lint is provided on the command line (see Options), gawk warns that passing an array argument is not portable. If --posix is supplied, using an array argument is a fatal error.
match(string, regexp)
Search string for the longest, leftmost substring matched by the regular expression, regexp and return the character position, or index, at which that substring begins (one, if it starts at the beginning of string). If no match is found, return zero.
The regexp argument may be either a regexp constant (/.../) or a string constant ("..."). In the latter case, the string is treated as a regexp to be matched.
The order of the first two arguments is backwards from most other string functions that work with regular expressions, such as sub() and gsub(). It might help to remember that for match(), the order is the same as for the ‘~’ operator: ‘string ~ regexp’.
The match() function sets the built-in variable RSTART to the index. It also sets the built-in variable RLENGTH to the length in characters of the matched substring. If no match is found, RSTART is set to zero, and RLENGTH to 0.
For example:
{
if ($1 == "FIND")
regex = $2
else {
where = match($0, regex)
if (where != 0)
print "Match of", regex, "found at",
where, "in", $0
}
}
This program looks for lines that match the regular expression stored in the variable regex. This regular expression can be changed. If the first word on a line is ‘FIND’, regex is changed to be the second word on that line. Therefore, if given:
FIND ru+n
My program runs
but not very quickly
FIND Melvin
JF+KM
This line is property of Reality Engineering Co.
Melvin was here.
awk prints:
Match of ru+n found at 12 in My program runs
Match of Melvin found at 1 in Melvin was here.
If array is present, it is cleared, and then the zeroth element of array is set to the entire portion of string matched by regexp. If regexp contains parentheses, the integer-indexed elements of array are set to contain the portion of string matching the corresponding parenthesized subexpression. For example:
$ echo foooobazbarrrrr |
> gawk '{ match($0, /(fo+).+(bar*)/, arr)
> print arr[1], arr[2] }'
-| foooo barrrrr
In addition, multidimensional subscripts are available providing the start index and length of each matched subexpression:
$ echo foooobazbarrrrr |
> gawk '{ match($0, /(fo+).+(bar*)/, arr)
> print arr[1], arr[2]
> print arr[1, "start"], arr[1, "length"]
> print arr[2, "start"], arr[2, "length"]
> }'
-| foooo barrrrr
-| 1 5
-| 9 7
There may not be subscripts for the start and index for every parenthesized subexpression, since they may not all have matched text; thus they should be tested for with the in operator (see Reference to Elements).
split(string, array [, fieldsep [, seps ] ])
Divide string into pieces separated by fieldsep and store the pieces in array and the separator strings in the seps array. The first piece is stored in array[1], the second piece in array[2], and so forth. The string value of the third argument, fieldsep, is a regexp describing where to split string (much as FS can be a regexp describing where to split input records; see Regexp Field Splitting). If fieldsep is omitted, the value of FS is used. split() returns the number of elements created. seps is a gawk extension with seps[i] being the separator string between array[i] and array[i+1]. If fieldsep is a single space then any leading whitespace goes into seps[0] and any trailing whitespace goes into seps[n] where n is the return value of split() (that is, the number of elements in array).
The split() function splits strings into pieces in a manner similar to the way input lines are split into fields. For example:
split("cul-de-sac", a, "-", seps)
splits the string ‘cul-de-sac’ into three fields using ‘-’ as the separator. It sets the contents of the array a as follows:
a[1] = "cul"
a[2] = "de"
a[3] = "sac"
and sets the contents of the array seps as follows:
seps[1] = "-"
seps[2] = "-"
The value returned by this call to split() is three.
As with input field-splitting, when the value of fieldsep is " ", leading and trailing whitespace is ignored in values assigned to the elements of array but not in seps, and the elements are separated by runs of whitespace. Also as with input field-splitting, if fieldsep is the null string, each individual character in the string is split into its own array element. (c.e.)
Note, however, that RS has no effect on the way split() works. Even though ‘RS = ""’ causes newline to also be an input field separator, this does not affect how split() splits strings.
Modern implementations of awk, including gawk, allow the third argument to be a regexp constant (/abc/) as well as a string. (d.c.) The POSIX standard allows this as well. See Computed Regexps, for a discussion of the difference between using a string constant or a regexp constant, and the implications for writing your program correctly.
Before splitting the string, split() deletes any previously existing elements in the arrays array and seps.
If string is null, the array has no elements. (So this is a portable way to delete an entire array with one statement. See Delete.)
If string does not match fieldsep at all (but is not null), array has one element only. The value of that element is the original string.
sprintf(format, expression1, ...)
Return (without printing) the string that printf would have printed out with the same arguments (see Printf). For example:
pival = sprintf("pi = %.2f (approx.)", 22/7)
assigns the string ‘pi = 3.14 (approx.)’ to the variable pival.
sub(regexp, replacement [, target])
Search target, which is treated as a string, for the leftmost, longest substring matched by the regular expression regexp. Modify the entire string by replacing the matched text with replacement. The modified string becomes the new value of target. Return the number of substitutions made (zero or one).
The regexp argument may be either a regexp constant (/.../) or a string constant ("..."). In the latter case, the string is treated as a regexp to be matched. See Computed Regexps, for a discussion of the difference between the two forms, and the implications for writing your program correctly.
This function is peculiar because target is not simply used to compute a value, and not just any expression will do—it must be a variable, field, or array element so that sub() can store a modified value there. If this argument is omitted, then the default is to use and alter $0.42 For example:
str = "water, water, everywhere"
sub(/at/, "ith", str)
sets str to ‘wither, water, everywhere’, by replacing the leftmost longest occurrence of ‘at’ with ‘ith’.
If the special character ‘&’ appears in replacement, it stands for the precise substring that was matched by regexp. (If the regexp can match more than one string, then this precise substring may vary.) For example:
{ sub(/candidate/, "& and his wife"); print }
changes the first occurrence of ‘candidate’ to ‘candidate and his wife’ on each input line. Here is another example:
$ awk 'BEGIN {
> str = "daabaaa"
> sub(/a+/, "C&C", str)
> print str
> }'
-| dCaaCbaaa
This shows how ‘&’ can represent a nonconstant string and also illustrates the “leftmost, longest” rule in regexp matching (see Leftmost Longest).
The effect of this special character (‘&’) can be turned off by putting a backslash before it in the string. As usual, to insert one backslash in the string, you must write two backslashes. Therefore, write ‘\\&’ in a string constant to include a literal ‘&’ in the replacement. For example, the following shows how to replace the first ‘|’ on each line with an ‘&’:
{ sub(/\|/, "\\&"); print }
As mentioned, the third argument to sub() must be a variable, field or array element. Some versions of awk allow the third argument to be an expression that is not an lvalue. In such a case, sub() still searches for the pattern and returns zero or one, but the result of the substitution (if any) is thrown away because there is no place to put it. Such versions of awk accept expressions like the following:
sub(/USA/, "United States", "the USA and Canada")
For historical compatibility, gawk accepts such erroneous code. However, using any other nonchangeable object as the third parameter causes a fatal error and your program will not run.
Finally, if the regexp is not a regexp constant, it is converted into a string, and then the value of that string is treated as the regexp to match.
substr(string, start [, length])
Return a length-character-long substring of string, starting at character number start. The first character of a string is character number one.43 For example, substr("washington", 5, 3) returns "ing".
If length is not present, substr() returns the whole suffix of string that begins at character number start. For example, substr("washington", 5) returns "ington". The whole suffix is also returned if length is greater than the number of characters remaining in the string, counting from character start.
If start is less than one, substr() treats it as if it was one. (POSIX doesn't specify what to do in this case: Brian Kernighan's awk acts this way, and therefore gawk does too.) If start is greater than the number of characters in the string, substr() returns the null string. Similarly, if length is present but less than or equal to zero, the null string is returned.
The string returned by substr() cannot be assigned. Thus, it is a mistake to attempt to change a portion of a string, as shown in the following example:
string = "abcdef"
# try to get "abCDEf", won't work
substr(string, 3, 3) = "CDE"
It is also a mistake to use substr() as the third argument of sub() or gsub():
gsub(/xyz/, "pdq", substr($0, 5, 20)) # WRONG
(Some commercial versions of awk treat substr() as assignable, but doing so is not portable.)
If you need to replace bits and pieces of a string, combine substr() with string concatenation, in the following manner:
string = "abcdef"
...
string = substr(string, 1, 2) "CDE" substr(string, 6)
tolower(string)
Return a copy of string, with each uppercase character in the string replaced with its corresponding lowercase character. Nonalphabetic characters are left unchanged. For example, tolower("MiXeD cAsE 123") returns "mixed case 123".
toupper(string)
Return a copy of string, with each lowercase character in the string replaced with its corresponding uppercase character. Nonalphabetic characters are left unchanged. For example, toupper("MiXeD cAsE 123") returns "MIXED CASE 123".
发表评论
-
linux 查看不同进制文件
2018-01-31 11:43 328hexdump -
iptables 从链、表开始理解
2015-06-24 14:26 498iptables 不清楚的同学可以在看这里的比较全面的文章ht ... -
CentOS---网络配置详解
2015-06-24 13:44 498http://blog.chinaunix.net/uid-2 ... -
linux中RSYNC进行网站增量备份配置
2015-06-17 13:23 453linux中RSYNC进行网站增量备份配置 http://w ... -
Linux启动过程详解
2015-06-03 16:02 322http://blog.chinaunix.net/uid-2 ... -
谈谈varnish,squid,apache,nginx缓存的对比
2015-04-03 13:24 620http://www.cnblogs.com/google4y ... -
OpenSSL生成证书
2015-03-09 11:02 609要生成证书的目录下建立几个文件和文件夹,有./demoCA/ ... -
sysctl配置
2015-02-10 16:50 625Sysctl是一个允许您改变正在运行中的Linux系统的接口。 ... -
mysql 增删改查
2015-02-03 16:31 507mysql实时监控工具: //create database ... -
利用OpenSSL生成库和命令程序
2015-01-31 10:09 648在生成的命令程序中包括对加/解密算法的测试,openssl程序 ... -
more less 实用技巧
2015-01-27 20:30 489more +10 xxx.log more +/10:00:0 ... -
nginx 使用详细解
2015-01-27 16:07 733http://www.linuxidc.com/Linux/2 ... -
Iptable 详解
2015-01-23 13:52 551## 将7888端口映射到8080 ... -
弟弟(dd)是个好命令
2014-07-18 14:34 676dd 使用dd这个linux命令可以创建一定大小文件。 l ... -
查看文件编码
2014-07-05 14:31 490查看文件编码 在Linux中查看文件编码可以通过以下几种方式: ... -
curl
2014-06-18 12:32 1188link:http://curl.haxx.se/docs/m ... -
nginx 504初级解决方案
2014-06-18 10:12 839large_client_header_buffers 4 1 ... -
memcached dump
2014-06-13 09:51 525yum install libmemcached; ./mem ... -
模块查看依懒
2014-06-08 11:18 401depmod -a -
pwdx等几个proc工具
2014-06-06 12:34 1144分类: pwdx pid:显示进程的命令所在的目录 ptree ...
相关推荐
算数函数、字符串函数、其它一般函数、时间函数
若你使用过 Shell 中的 awk 工具,会发现用它来分割字符串是非常方便的。特别是多个连续空格会被当做一个处理。 [root@localhost ~]# cat demo.txt hello world [root@localhost ~]# [root@localhost ~]# awk ...
awk命令常用用法整理;加入了自己在平时运用中的...awk有许多强大的字符串函数 gsub(r,s) #在整个$0中,用s代替r gsub(r,s,t) 在整个t中,用s代替r index(s,t) 返回s中字符串t的第一位置 length(s) 返回s长度 。。。
内置字符串函数gsub函数indexlength 1.awk–“样式扫描和处理语言” awk是一种很棒的语言,它适合文本处理和报表生成,其语法较为常见,借鉴了某些语言的一些精华。在linux系统日常处理工作中,发挥很重要的工作。 ...
本文实例讲述了php实现字符串反转输出的方法。... 您可能感兴趣的文章:php实现字符串翻转的方法利用perl、python、php、shell、sed、awk、c 实现字符串的翻转php中实现字符串翻转的方法PHP 实现字符串翻转(包含
文章目录表达式统计input文件中的空白行平均值的计算系统变量格式化输出awk的ascii字符的转换awk的字符型字符的转换printf 修饰符的栗子内置字符串函数举个例子 表达式 统计input文件中的空白行 平均值的计算 ...
AWK 是该编程语言本身的名称,它编写于 1977 年。其名称是三个主要作者的姓的首字母缩写:Drs....事实上,其中许多特性,包括控制语句和字符串函数,如 printf 和 sprintf,基本上是相同的。然而,也存在着一些差异。
关于linux下的awk 如调用awk的方式,与正则表达式的结合,内置变量 操作符,内置的字符串函数,格式化函数printf等
三剑客过滤长字符串 记一次过滤文件内容,三剑客awk、grep、...且看,统计字符串长度,用到招式 length() 函数 [root@centos]# echo hello | awk '{print length($1)}' 5 如看官所愿,得到字符串的长度 5 连招,加 if
1.5 AWK的内置函数......................................................................................................................7 1.6 在命令行使用AWK..............................................
需要对字符串查找其中某个字符最后出现的位置,这个在PHP (strrpos)或者Perl (rindex)里面都有现成函数可用的功能,在Shell里面居然一时想不出个道道来。在论坛上发贴也没人解答(不知道是问题太简单还是真的很高深...
29.awk打印传入字符串的第n个分隔域 37 30.在awk中使用shell中的变量 37 31.在某个目录下查找包含特定字符串的文件 返回文件名称 39 五.其它命令 39 1.eval命令:可用于动态生成和执行代码 39 2.exit n:退出...
简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各种分析处理。 awk有3个不同版本: awk、nawk和gawk,未作特别说明,一般指gawk,gawk 是 AWK 的 GNU 版本。 awk其名称得自于它的...
在学习awk之前我们应该都学过sed,grep,tr,cut等等命令,这些命令都是为了方便我们对Linux下文本和数据的处理,但是我们会发现很多时候这些命令并不能一下子就完全解决我们的需求,很多时候我们都需要使用管道符结合...
9.2.9 内置的字符串函数 78 9.2.10 字符串屏蔽序列 80 9.2.11 awk输出函数printf 81 9.2.12 printf修饰符 81 9.2.13 awk数组 86 9.3 小结 88 第10章 sed 用法介绍 89 10.1 sed怎样读取数据 89 10.2 调用sed 89 ...
9.2.9 内置的字符串函数 78 9.2.10 字符串屏蔽序列 80 9.2.11 awk输出函数printf 81 9.2.12 printf修饰符 81 9.2.13 awk数组 86 9.3 小结 88 第10章 sed 用法介绍 89 10.1 sed怎样读取数据 89 10.2 调用sed 89 ...
2.7. 以字符串为单位的I/O函数 2.8. 以记录为单位的I/O函数 2.9. 格式化I/O函数 2.10. C标准库的I/O缓冲区 2.11. 本节综合练习 3. 数值字符串转换函数 4. 分配内存的函数 26. 链表、二叉树和哈希表 1. 链表 1.1. ...
9.2.9 内置的字符串函数 78 9.2.10 字符串屏蔽序列 80 9.2.11 awk输出函数printf 81 9.2.12 printf修饰符 81 9.2.13 awk数组 86 9.3 小结 88 第10章 sed 用法介绍 89 10.1 sed怎样读取数据 89 10.2 调用sed 89 ...
9.2.9 内置的字符串函数 78 9.2.10 字符串屏蔽序列 80 9.2.11 awk输出函数printf 81 9.2.12 printf修饰符 81 9.2.13 awk数组 86 9.3 小结 88 第10章 sed 用法介绍 89 10.1 sed怎样读取数据 89 10.2 调用sed 89 ...
shell基础知识、shell字符串处理、shell表达式与运算符、shell流程控制、shell函数与数组、shell正则表达式、shell文本处理三剑客(grep、sed、awk)、shell标准输入、输出和错误、shell信号发送与捕捉、shell编程时...