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|actor
5678|jacknicholson|director
4321|christianbale|actor
file2.txt -- Contains the movies of the actors.
1234|oneflewovercuckoosnest^asgoodasitgets
5678|theshining
4321|batmanbegins^darkknight
file3.txt -- Residence of the actors.
1234|california
5678|hollywoodstudios
4321|losangeles
I 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.txt
The above command will make my first file (file1.txt
) as,
1234|jacknicholson|actor
5678|jacknicholson|director
4321|christianbale|actor
I 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.