bash print rows that contain substring in field code example
Example: bash print rows that contain substring in field
# Basic syntax using awk:
awk -F'delimiter' 'index($field#, "substring")' input_file
# Where:
# - -F'delimiter' is the delimiter used in the input_file
# - index checks whether substring is found in the specified field. If
# it is, that line is printed
# Example usage using awk:
# Say you have a file with the following lines and want to print lines
# that contain the substring "target" in the second column
tab separated file full
of targeted words in
targeted columns of text
# Running
awk -F'\t' 'index($2, "target")' input_file
# Would return:
of targeted words in
# Note, you can use $0 to look for the substring in the whole row