拆分使用字符串作为分隔符awk的字符串 [英] Split a string using a string as delimiter in awk
问题描述
系统:的Solaris
我试图用分隔符为另一个字符串分割字符串
例如:
主字符串: /为/ asdasd / asdasd /根/ asdqwe / ASD / asssdd /
我想从根的子字符串分割成两部分这使得
$ 1 = /为/ asdasd / asdasd /
和
$ 2 = asdqwe / ASD / asssdd /
这是我使用FS实现了code,但它不工作:
回音/为/ asdasd / asdasd /根/ asdqwe / ASD / asssdd / | AWK
BEGIN {FS =根} {打印$ 2}'
据在这里工作,除了额外的 /
上你不处理的前面。也许你想根/
为您的分隔符?它也可能有必要使用一个新的 AWK
;的Solaris仍然船舶古V7 Unix的 AWK
为的/ usr / bin中/ AWK
,POSIX兼容的 AWK
是的/ usr / bin中/ NAWK
。
System : Solaris I am trying to split a string using the delimiter as another string
For example:
The main string is : /as/asdasd/asdasd/root/asdqwe/asd/asssdd/
I wanna split this into two part from the "root" substring such that
$1 = /as/asdasd/asdasd/
and
$2 = asdqwe/asd/asssdd/
This is the code I implemented using FS, but it doesn't work:
echo /as/asdasd/asdasd/root/asdqwe/asd/asssdd/ | awk '
BEGIN { FS = "root" } { print $2 }'
It works here, aside from the extra /
on the front which you don't handle. Maybe you want "root/"
as your delimiter? It may also be necessary to use a newer awk
; Solaris still ships the ancient V7 Unix awk
as /usr/bin/awk
, POSIX-compliant awk
is /usr/bin/nawk
.
这篇关于拆分使用字符串作为分隔符awk的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!