I have 3 input files all having the same number of lines. I have come up with a movie example to make the question look interesting. file1.txt -- Essentially contains the actor names. 1234|jacknicholson|actor5678|jacknicholson|director4321|christianbale|actorfile2.txt -- Contains the movies of the actors.1234|oneflewovercuckoosnest^asgoodasitgets5678|theshining4321|batmanbegins^darkknightfile3.txt -- Residence of the actors.1234|california5678|hollywoodstudios4321|losangelesI am splitting the first input file based on the condition that if names are equal, I need to apply some algorithm. The command is as below. awk -F '|' 'NR>1 && $2 != prev {print } {prev=$2; print}' file1.txtThe above command will make my first file (file1.txt) as,1234|jacknicholson|actor5678|jacknicholson|director4321|christianbale|actorI need to introduce the space at the same position in the remaining 2 files too so that I can apply my algorithm. One approach that comes to my mind is, store the position of spaces in the file1.txt in an array and then when I encounter that position in the remaining 2 files, introduce the spaces. 
introduce line break at the same position based on another file
awk;perl
To introduce a blank line in a file at the same position as changes in actors in file1.txt, try:$ awk -F '|' '{save=$0; getline<file1.txt} NR>1 && $2!=prev {print } {prev=$2; print save}' file2.txt1234|oneflewovercuckoosnest^asgoodasitgets5678|theshining4321|batmanbegins^darkknightThe above works quite a bit like your code except that it is extended to read two files at the same time.  It reads from file2.txt and saves the line in the variable save.  If then reads from file.txt, and using the same logic as your code, determines if the actor changes and, if so, prints a line break.  It then prints the line it received from file2.txt.