Adding 2 awk
solutions to the mix here.
1st solution(simpler solution): With simple awk
and any version of awk
.
awk '!/T/ || /TH/' Input_file
Checking 2 conditions:
If a line doesn't contain T
OR
If a line contains TH
then:
If any of above condition is TRUE then print that line simply.
2nd solution(GNU awk
specific): Using GNU awk
using match
function where mentioning regex (T)(.|$)
and using match
function's array creation capability.
awk '
!/T/{
print
next
}
match($0,/(T)(.|$)/,arr) && arr[1]=="T" && arr[2]=="H"
' Input_file
Explanation: firstly checking if a line doesn't have T
then print that simply. Then using match
function of awk
to match T
followed by any character OR end of the line. Since these are getting stored into 2 capturing groups so checking if array arr's 1st element is T and 2nd element is H then print that line.