Closest you can contact GNU awk FPAT :
$ awk '{print $1}' FPAT='(^[^:]+)|(:.*)' file one $ awk '{print $2}' FPAT='(^[^:]+)|(:.*)' file :two:three:four:five:six seven:eight
But $2 will include the main delimiter, but you can use substr to fix this:
$ awk '{print substr($2,2)}' FPAT='(^[^:]+)|(:.*)' file two:three:four:five:six seven:eight
So, all together:
$ awk '{print $1, substr($2,2)}' FPAT='(^[^:]+)|(:.*)' file one two:three:four:five:six seven:eight
Saving substr results back to $2 will allow us to continue processing on $2 without the main delimiter:
$ awk '{$2=substr($2,2); print $1,$2}' FPAT='(^[^:]+)|(:.*)' file one two:three:four:five:six seven:eight
Solution that should work with mawk 1.3.3 :
awk '{n=index($0,":");s=$0;$1=substr(s,1,n-1);$2=substr(s,n+1);print $1}' FS='\0' one awk '{n=index($0,":");s=$0;$1=substr(s,1,n-1);$2=substr(s,n+1);print $2}' FS='\0' two:three:four five:six:seven awk '{n=index($0,":");s=$0;$1=substr(s,1,n-1);$2=substr(s,n+1);print $1,$2}' FS='\0' one two:three:four five:six:seven
Chris seymour
source share