I am iterating record by record through a file as below,
A,B
A,C
A,D
B,E
B,F
E,G
E,H
The same file should look like in the final output as below,
A,B
B,E
E,G
E,H
B,F
A,C
A,D
So while iterating, it should remove records from the same file & paste inside in the same file.
How can we achieve this functionality of removing & pasting records in the same file?
I can think of pseudo code as below;
CODE START
cat File1.txt | while read row; do
col1=`echo $row | awk -F","'{print $1}'`
col2=`echo $row | awk -F","'{print $2}'`
#if col2 has first column occurance in the file
awk /^"$col2"/ filename > Temp.txt
# HOW TO REMOVE CONTENTS from File1.txt which starts with $col2
# will echo Temp.txt >> File1.txt ... will paste the records in between?
done < File1.txt
CODE END
I hope I am clear in passing my problem.