change field separator only from nth field until NF

view full story

http://www.unix.com – Hi ! input: Code: 111|222|333|aaa|bbb|ccc 999|888|777|nnn|kkk 444|666|555|eee|ttt|ooo|ppp With awk, I am trying to change the FS "|" to "; " only from the 4th field until the end (the number of fields vary between records). In order to get: Code: 111|222|333|aaa; bbb; ccc 999|888|777|nnn; kkk 444|666|555|eee; ttt; ooo; ppp I tried something like: Code: gawk 'BEGIN{FS=OFS="|"}{for(i=5; i<=NF; i++) $4 = $4 ($4?"; ":"")$i}1' input It works for the 4th field, but it also prints the original fields from $5 to $NF af (HowTos)