shell - Split a string using a string as delimiter in awk -


System: Solaris I'm trying to split a string into another string

For example:


The main string is: / as / asdasd / asdasd / root / asdqwe / asd / asssdd /

I Part of the "root" substrings I want to divide into two such as

$ 1 = / as / asdasd / asdasd /

and

$ 2 = asdqwe / asd / asssdd /

This is the code that I have implemented using FS, but this is Gum does not:

  echo / as / asdasd / asdasd / root / asdqwe / asd / asssdd / | Awk 'BEGIN {FS = "root"} {print $ 2}' '   

Works here, aside from additional / which you do not handle, maybe you want "root /" as your delimiter? It may also be necessary to use a new awk ; Solaris is still the old V7 Unix awk as / usr / bin / awk , posix-compatible awk / usr / bin / Nose .

Comments