I have an issue when I try to extract the first word after grep matches my pattern .Let me show you an example : cat test.txt[profile dev]xxxxxx[profile prod]xxxxxxnow I want to extract the word after 'profile' and eventually assign it into a variable I tried with grep and awk but it seems I can't extract only the word grep -oP '(?<=profile\s/)\w+' /test.txt returns nothing also with awk: awk '/^profile / {print $1}' /text.txt maybe its because of the brackets or I don't know , can you help me with a suggestion? 
Extract first word after pattern that includes `[...]`
text processing;awk;grep
Your Awk pattern is failing because the word profile does not start the record, [profile does...awk '/^\[profile/ {gsub(/]/,); print $2}' test.txtdevprodAnother approach would be to load an array, using split:awk -F'[][]' '/profile/ {p=split($2,profiles, ); print profiles[2]}' test.txtdevprod