I have a tab-delimited file of entries that have a start and end position
# Name \t Start \t End
Name1 \t 1 \t 3
Name2 \t 7 \t 9
Name3 \t 5 \t 8
Name4 \t 5 \t 6
I want to delete lines that overlap with earlier lines. In this example, the desired output would be
Name1 \t 1 \t 3
Name2 \t 7 \t 9
Name4 \t 5 \t 6
What I have so far:
#!/bin/bash
while IFS=$'\n' read line; do
# Assign variable names
name=$(echo $line | cut -f 1)
start=$(echo $line | cut -f 2)
end=$(echo $line | cut -f 3)
# I envision an if statement structured so that:
# if [ $end < $PreviousStart ] || [ $start > $PreviousEnd ] ; then echo $line >> output.txt
done < file.txt
This is where I get stuck because I would need to check each line of output.txt (all the previous lines from my original file) and only print $line if the if statement is satisfied for all current lines of output.txt. I was thinking awk may have a solution for this that is less circuitous...
Any help is greatly appreciated
Assumptions:
One
awkidea:This generates: