split word

Hi all,

Infile:

1|2|3|test james ke the one |value
1|2|3|test the value|comp
1|2|3|test james|value
1|2|3|one two three|value

I need split the 4th delimiter value into 3 fields based on below condition.if 4th field contains "ke loc" or "the" then i should not consider it is word and need to take following word also
otherwise take it is word and write in output file separated by |

Expected outfile :

1|2|3|test|james|ke the one |value
1|2|3|test|the value||comp
1|2|3|test|james|||value
1|2|3|one|two|three|value

Thanks in advance.

hmm, you still not following the [code] rules :frowning:

Please use the [CODE] tags

Sorry. Next time onwards I will follow CODE tags .

---------- Post updated at 08:42 AM ---------- Previous update was at 06:15 AM ----------

Any help

what u tried so far ?

I tried some of the awk command combination. But no luck sir.

# awk -F'[ |]' '{for(i=0;++i<=NF;){if($i){printf $i ((i==NF)?ORS:($i~"the|ke")?OFS:"|")}}}' file
1|2|3|test|james|ke the one|value
1|2|3|test|the value|comp
1|2|3|test|james|value
1|2|3|one|two|three|value
1 Like

Thanks Danmero. It is working now.