AWK is a quite decent tool for such purpose as well. Here's sample run of code:
$ awk 'NR == 1 {print} NR != 1 && $0!~/ID Data1 Data2/' rmLines.txt | head -n 10
ID Data1 Data2
1 100 100
100 200
3 200 100
1 100 100
100 200
3 200 100
1 100 100
100 200
3 200 100
Break down:
NR == 1 {print}
tells us to print first line of text file
NR != 1 && $0!~/ID Data1 Data2/
logical operator &&
tells AWK to print line that is not equal to 1 and doesn't contain ID Data1 Data2
. Note the lack of {print}
part; in awk if a test condition is evaluated to true,it is assumed for line to be printed.
| head -n 10
is just a tiny addition to limit output to only first 10 lines. Not relevant to the AWK
part itself, only used for demo purpose.
If you want that in a file, redirect the output of the command by appending > newFile.txt
at the end of command, like so:
awk 'NR == 1 {print} NR != 1 && $0!~/ID Data1 Data2/' rmLines.txt > newFile.txt
How does it hold up ? Pretty good actually:
$ time awk 'NR == 1 {print} NR != 1 && $0!~/ID Data1 Data2/' rmLines.txt > /dev/null
0m3.60s real 0m3.53s user 0m0.06s system
Side note
The generated sample file was done with for looping from one to million and printing first four lines of your file (so 4 lines times million equals 4 millions of lines ), which took 0.09 seconds, by the way.
awk 'BEGIN{ for(i=1;i<=1000000;i++) printf("ID Data1 Data2\n1 100 100\n 100 200\n3 200 100\n"); }' > rmLines.txt