grep -B 1 -i "Northbound to" file1 > file2 grep -B 1 -i "Southbound to" file1 >> file2