I'm trying to write a shell script that searches in a file specified as argument $1 for a regex and writes the found subpattern into a variable I can then use.
let's say my script is called 'dosth.sh' and I have a file 'plot.gp' with the line
set output 'test.tex'
If I now execute 'dosth.sh plot.gp' the script should extract 'test.tex' from plot.gp and write it to a variable.
How is that possible with grep or others?
Thanks and regards, Jan Oliver
using " instead of ' and the line above does the job.
value=$( awk -F"'" '$1 == "set output " {print $2}' somefile )
dosth.sh:
this can be used as:
then the found strings are stored in the variable
VALUE
You can also give the regexp over by some arguments (asked for the filename by the script):
dosth.sh:
which can be used like:
Maybe this link is helpful for you: Link
You could try something along the lines of
(Note that you will retain the quotes in
$value