Skip to main content
deleted 1 character in body
Source Link
don_crissti
  • 85.7k
  • 31
  • 234
  • 263

You can indeed combinedcombine awk and grep:

awk 'BEGIN{rv=1}                      # Default return value is 1
     tolower($0) ~ /^some_phrase/{    # Case insensitive search 
         if($2 != ""){                # If $2 is not empty,
            print $2                  # print the value,
            rv=0                      # and set the return value
         } 
         exit                         # one match, do not process any more line 
     } 
     END{exit rv}
' test.txt

You can indeed combined awk and grep:

awk 'BEGIN{rv=1}                      # Default return value is 1
     tolower($0) ~ /^some_phrase/{    # Case insensitive search 
         if($2 != ""){                # If $2 is not empty,
            print $2                  # print the value,
            rv=0                      # and set the return value
         } 
         exit                         # one match, do not process any more line 
     } 
     END{exit rv}
' test.txt

You can indeed combine awk and grep:

awk 'BEGIN{rv=1}                      # Default return value is 1
     tolower($0) ~ /^some_phrase/{    # Case insensitive search 
         if($2 != ""){                # If $2 is not empty,
            print $2                  # print the value,
            rv=0                      # and set the return value
         } 
         exit                         # one match, do not process any more line 
     } 
     END{exit rv}
' test.txt
Source Link
oliv
  • 2.6k
  • 11
  • 15

You can indeed combined awk and grep:

awk 'BEGIN{rv=1}                      # Default return value is 1
     tolower($0) ~ /^some_phrase/{    # Case insensitive search 
         if($2 != ""){                # If $2 is not empty,
            print $2                  # print the value,
            rv=0                      # and set the return value
         } 
         exit                         # one match, do not process any more line 
     } 
     END{exit rv}
' test.txt