Simple bash/awk/sed scripting question
I'm a little bit confused about the use of awk/sed in a script. I've skimmed through the guides to both and it seems to me like they only operate on files/stdin/stdout, is that right? What I am trying to do is write a simple expression to extract a substring from a bash variable and re-assign the variable to that substring. Specifically the variable consists of an executable's name (+ it's path) and it's inputs. So something like this:
Code:
exec_target="/usr/bin/gcc -c my_program my_program.c" I know there are multiple ways of doing this and I could do it in the blink of an eye if this script I wrote was in Perl, but what's a fast, simple way of doing it in the Bash world and what tool (awk/sed) is best suited for this type of task? Thanks :) |
I think this will do what you want, but I may be barking up the wrong tree...
Code:
exec_target=$(echo $exec_target | sed -e 's/.*\///') |
Oh, so sed uses the same matching operator as perl does it? Well that's good to know. :D
Yeah that command yields this: Code:
exec_target="/usr/bin/gcc -c my_program my_program.c" |
exec_target=`echo $exec_target|cut -d' ' -f1`
echo $exec_target /usr/bin/gcc exec_target=`basename $exec_target` echo $exec_target gcc |
Awk is such a lovely tool ;)
Code:
[/home/soumen/tmp] $ exec_target="/usr/bin/gcc -c my_program my_program.c" |
All times are GMT -5. The time now is 08:23 PM. |