- 浏览: 211291 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (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 366hexdump -
iptables 从链、表开始理解
2015-06-24 14:26 534iptables 不清楚的同学可以在看这里的比较全面的文章ht ... -
CentOS---网络配置详解
2015-06-24 13:44 533http://blog.chinaunix.net/uid-2 ... -
linux中RSYNC进行网站增量备份配置
2015-06-17 13:23 477linux中RSYNC进行网站增量备份配置 http://w ... -
Linux启动过程详解
2015-06-03 16:02 354http://blog.chinaunix.net/uid-2 ... -
谈谈varnish,squid,apache,nginx缓存的对比
2015-04-03 13:24 668http://www.cnblogs.com/google4y ... -
OpenSSL生成证书
2015-03-09 11:02 641要生成证书的目录下建立几个文件和文件夹,有./demoCA/ ... -
sysctl配置
2015-02-10 16:50 685Sysctl是一个允许您改变正在运行中的Linux系统的接口。 ... -
mysql 增删改查
2015-02-03 16:31 535mysql实时监控工具: //create database ... -
利用OpenSSL生成库和命令程序
2015-01-31 10:09 691在生成的命令程序中包括对加/解密算法的测试,openssl程序 ... -
more less 实用技巧
2015-01-27 20:30 527more +10 xxx.log more +/10:00:0 ... -
nginx 使用详细解
2015-01-27 16:07 798http://www.linuxidc.com/Linux/2 ... -
Iptable 详解
2015-01-23 13:52 618## 将7888端口映射到8080 ... -
弟弟(dd)是个好命令
2014-07-18 14:34 714dd 使用dd这个linux命令可以创建一定大小文件。 l ... -
查看文件编码
2014-07-05 14:31 513查看文件编码 在Linux中查看文件编码可以通过以下几种方式: ... -
curl
2014-06-18 12:32 1231link:http://curl.haxx.se/docs/m ... -
nginx 504初级解决方案
2014-06-18 10:12 894large_client_header_buffers 4 1 ... -
memcached dump
2014-06-13 09:51 568yum install libmemcached; ./mem ... -
模块查看依懒
2014-06-08 11:18 455depmod -a -
pwdx等几个proc工具
2014-06-06 12:34 1194分类: pwdx pid:显示进程的命令所在的目录 ptree ...
相关推荐
在给定的文件信息中,我们探讨了AWK这一强大文本处理工具中的算数函数、字符串函数以及其他功能,包括时间函数。以下是对这些知识点的详细解释: ### 算数函数 1. **atan2(y,x)**:此函数计算坐标 (x,y) 的角度...
* 字符串函数:awk 中有多种字符串函数,如 sub、gsub、index、substr、split、length、match 等,用于对字符串进行操作。 * 数学函数:awk 中有多种数学函数,如 atan2、cos、exp、int、log、rand、sin、sqrt 等,...
以上内容详细介绍了 Linux 下 AWK 的内置函数,包括算术函数和字符串函数。这些函数可以帮助开发者在进行文本处理时更加灵活高效。通过这些函数,我们可以轻松实现数据过滤、字符串操作等功能,从而提高工作效率。
`awk` 是一种强大的文本处理语言,用于字符串操作非常灵活。 1. **使用 `split` 函数:** ```bash $ echo $var | awk '{printf("%d%s\n", split($0, var_arr, ""), var_arr[1])}' split 字符串到数组 var_arr 中...
awk 有多种函数,包括数学函数、字符串函数、时间函数等。数学函数包括 sqrt、sin、cos 等,字符串函数包括 substr、index、match 等,时间函数包括 systime、strftime 等。 awk 的应用 awk 的应用非常广泛,包括...
在日常的Shell脚本开发工作中,我们经常需要处理字符串,其中计算字符串长度是一个常见的需求。本文将详细介绍五种在Shell脚本中计算字符串长度的方法,并对每种方法进行详细的解析,帮助读者更好地理解和掌握这些...
awk 中可以使用内置字符串函数 gsub 来匹配模式,例如 awk 'gsub(/12101/,"hello") {print $0} END{print FILENAME}' tab1。 awk 中可以使用内置字符串函数 index 来匹配模式,例如 awk '{print index($2,"D")""t" ...
1. 使用 strRepeat 函数可以重复字符串,例如:STR_REPEAT=`strRepeat "$USER_NAME" 3`。 2. 使用 printf 命令可以构造字符串,例如:STR_TEMP=`printf "%s%s" "$STR_ZERO" "$USER_NAME"`。 五、字符串比较 Shell ...
书中详细介绍了字符串函数,如length、index、sub、gsub等,以及如何进行字符串的拼接和比较。此外,书中还涵盖了数组的使用,包括关联数组和数值数组,它们允许开发者存储和处理多组相关数据。 模式匹配是awk的一...
awk命令常用用法整理;加入了自己在平时运用中的...awk有许多强大的字符串函数 gsub(r,s) #在整个$0中,用s代替r gsub(r,s,t) 在整个t中,用s代替r index(s,t) 返回s中字符串t的第一位置 length(s) 返回s长度 。。。
### AWK基本的一些常用用法 #### AWK简介 AWK是一种强大的文本处理工具,它最初是为了方便地处理结构化数据而设计的。AWK语言不仅支持基础的文本处理功能,还提供了高级的数据处理能力,使得它在数据分析、报告生成...
- **函数**:awk提供了内置的数学和字符串处理函数,如length()、split()、substr()等。 - **自定义函数**:可以创建用户自定义函数来复用代码。 ### 5. 在Windows中使用AWK 虽然awk是Unix/Linux下的标准工具,但...
在编程世界中,awk 是一个强大的文本分析工具,尤其在处理和分割字符串方面表现出色,它能够优雅地处理多个连续空格。然而,在 Python 中,`str.split()` 方法默认会将每个空格视为一个分隔符,导致多个连续空格被...
- **内置函数**: 包括算术函数(如`+`、`-`、`*`、`/`)、字符串函数(如`length`、`index`、`substr`)和控制流程函数(如`if`、`for`、`while`)等。 - **表达式**: 用于计算或判断,结果可以影响操作的执行。 ...
* 使用 awk 分割字符串:`awk 'BEGIN {split("123#xuyunbo#aini", dong1, "#"); print dong1[1]}'` * 使用 awk 生成报表:`awk -f awk4.sh` awk 是一个功能强大且灵活的文本处理工具,广泛应用于 Linux 系统中的...
awk还具备大量的内置函数,这些函数可以分为数值函数、字符串函数和系统函数三类。数值函数包括了三角函数、指数、对数和平方根等。字符串函数有用于长度计算、索引查找、子字符串操作、字符串分割等,nawk和gawk...
- **运算和字符串操作**: Awk可以执行各种数学运算和字符串处理任务。 ### 3. Awk程序和命令结构 Awk程序通常由模式、操作或二者组合而成。模式决定执行哪些操作,操作则定义了当模式匹配时要执行的代码。Awk命令...
还可以进行字符串拼接和格式化输出: ```awk awk '{total += $2*$3; count++} END {print total, total/count}' input-file ``` ### AWK流程控制语句 AWK具有完整的流程控制语句,如 `if-else`、`while`、`for` 等...