Help with reformat data structure

view story

http://www.unix.com – Input file: Code: bv|111259484|pir||T49736_real_data bv|159484|pir||T9736_data_figure bv|113584|prf|T4736|truth bv|113584|pir||T4736_truth Desired output: Code: bv|111259484|pir|T49736|real_data bv|159484|pir|T9736|data_figure bv|113584|prf|T4736|truth bv|113584|pir|T4736|truth Once the program find "pir||" I hope to replace "pir||" into "pir|' and follow by replace the next shown "_" into "|" Command I try: Code: awk '{gsub(/pir||/,"pir|",$1);print}' input_file.txt I just able to replace the "pir||" (HowTos)