[bash] cutting text with sed
I'm looking for a way to cut of some text.
With the commando 'pwd' I list the current directory. (example: /home/cs/server05) With these to lines: SPATH="$(cd $(dirname $0);pwd)" ## /home/cs/server05 SNAME=`echo $SPATH | cut -f 4 -d/` ## server05 I'm able to read the full directory and cut of the last 8 values (static, always 8 characters). The next problem is that I want to read what's between /home/ and the /server05. This value is dynamic by name and length. I tried using sed but the commando below gives me "cs/server05". SERVER=`echo $SPATH | sed -e s/\.home\.\/''/` What do I need to change to get 'cs' ? |
Fixed it already!
SPATH="$(cd $(dirname $0);pwd)" ## /home/cs/server05 SVALUE=`echo $SPATH | cut -d/ -f3` echo $SVALUE |
cut -d/ -f3
Or is it more complex than that and you really need sed? |
First you can also get SNAME with:
SNAME=`basename $SPATH` for SERVER, you could try: SERVER=`echo $SPATH | sed -r 's#(.*)/(.*)/(.*)#\2#'` [edit] Ok, it seems you find a better way :) |
All times are GMT -5. The time now is 06:50 AM. |