我想打印第一个空格之后的所有内容。例如。给定
hello there
我想打印 hello there
,给定 what's up
我想打印 what's up
。
我写这篇文章时完全希望它能起作用:
{ print $0 }
match($0, /[^[:space:]].*$/) {
print $1
}
我认为正则表达式
/[^[:space:]].*$/
将匹配第一个非空格字符,然后 .*$
将匹配其后面的所有字符。
但是正则表达式似乎只捕获下一个空格:
$ echo hello there | awk -f after_indent.awk
hello there
hello
$1
全局被认为是第一个场,它不是比赛结果。您必须使用substr
才能获得比赛结果:
{ print $0 }
match($0, /[^[:space:]].*$/) {
print substr($0, RSTART, RLENGTH)
}