I have a file called "krylov_methods", which has text like this:
cg - preconditioned
cgne - normal equations
nash - cg subject to constraint
stcg - another method for constraints
gmres - general minimum residual
...
I need to extract the first word (character string) of each line, one by one, in a shell script and use it as a command line argument within that script. To extract the first word, I used the following command:
head -1 krylov_methods | tail -1 | awk '{print $1}'
head -2 krylov_methods | tail -1 | awk '{print $1}'
head -3 krylov_methods | tail -1 | awk '{print $1}'
...
This seems to work well for extracting the first word of each line one by one
However, I need to be able to store the character string as a variable for future use within the script. For example, since the first word of the first line of the file "krylov_methods" is the word "cg", I want to be able store "cg" to a variable called "method". Within the script, I would like for it to get something like:
method=cg
./execute $method
Is this possible to store the result of the 'head' command used within a shell script?