I have the following 0.txt file below separating content by columns (fields):
'Disinfectants', 'Brand A', 'Brand B', 'Brand C'
'brand A', 'below brand C', 'greater than brand B'
'brand B', 'greater than brand D', 'below brand A'
I would like to find (from the second column) every time a pattern (say "brand A") occurs, and print out the contents of the first column belonging to the line where this pattern is found. For both the content of the resulting file is like:
Disinfectants
brand B
I have seen other similar issues but only printing the column itself where the pattern was found, usually using grep.
EDIT UPDATE: from @jubilatious1 suggestion , I found a question (https://stackoverflow.com/a/9153113) on the OS as part of my search for a solution.
awk '/brand A/{ print substr( $1, RLENGTH )}' 0.txt > 1.txt
but my 1.txt output has been different than expected as it prints only part of the content of the first field (column):
'brand
'brand
Besides, just using awk '/brand A/{ print substr( $1, RLENGTH )}' I can't specify that the search only works from the second field (column) onwards for each line.
EDIT UPDATE 1: maybe just fix the output of awk '/brand A/{ print substr( $1, RLENGTH )}' so that correctly printing the contents of the fields in the first column is a first step.