用awk打印一行特定索引字符 [英] Using awk to print characters of specific index on a line
本文介绍了用awk打印一行特定索引字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好了,所以我知道这是很简单的使用$打印线的具体参数:
$猫文件
你好,世界$ AWK'{$打印1}文件
你好
但是,如果我想通过8打印字符2是什么?或3至7?这是可能使用awk?
解决方案
的awk'{打印SUBSTR(0,2,6 $)}'文件
有关SUBSTR()的语法是
SUBSTR(字符串,开始索引,长度)
Alright, so I know it is quite simple to print specific arguments of a line using $:
$ cat file
hello world
$ awk '{print $1}' file
hello
But what if I want to print chars 2 through 8? or 3 through 7? Is that possible with awk?
解决方案
awk '{print substr($0,2,6)}' file
the syntax for substr() is
substr(string,start index,length)
这篇关于用awk打印一行特定索引字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文