I have a file that looks like this:-config1-config2 param2-config3 param3a param3b-config4 param4and I can use the following to extract param2:echo $(<file) | cut -d' ' -f3However I would like to fix it such that I always get the word after-config2, such that if these get re-arranged or something isinserted, my command will still work. What should I be looking at?Clarification: there may be more than one params on any given line (or none at all), however there will always be at most one -config option per line.
How to find the word after a given pattern using cut?
text processing;cut
I would use awk for thisawk '/^-config2/ {print $2}' fileIt print the second argument of lines starting with -config2. The ^ means the beginning of the line.