qeldroma Posted October 20, 2003 Report Share Posted October 20, 2003 I want to filter a variable for slashes: var=asdf/tzui echo ${var#/} Does not work, it filters only lines. So i have to find a way to filter the contents of a variable for / or and to change it in something else, p.e. a - var=asdf/tzui result=.........var../..-..... echo $result should lead into "asdf-tzui"... Quote Link to comment Share on other sites More sharing options...
Qchem Posted October 20, 2003 Report Share Posted October 20, 2003 seeing as though you don't want to use sed i've come up with a dirty hack var=asdf/tzui part1=`echo $var | cut -d/ -f 1` part2=`echo $var | cut -d/ -f 2` result=`echo $part1-$part2` echo $result which gives asdf-tzui is this what you want?? Quote Link to comment Share on other sites More sharing options...
qeldroma Posted October 20, 2003 Author Report Share Posted October 20, 2003 Yes it does, too ;-) Found another now: echo ${var///} Quote Link to comment Share on other sites More sharing options...
Qchem Posted October 20, 2003 Report Share Posted October 20, 2003 Hmm, I believe your way is slightly less dirty!!! :wink: Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted October 21, 2003 Report Share Posted October 21, 2003 hey qeldroma, would you mind explaining the hash marks and slashes inside the reference notation? what does it actually do? i know its in the man page or tldp but i only have windows so please spoil me. ;) ciao! Quote Link to comment Share on other sites More sharing options...
qeldroma Posted October 24, 2003 Author Report Share Posted October 24, 2003 It's a possibility only available in BASH and Kornshell. If you've got a variable like $var, you can echo the filtered variable: echo ${var/...} Where ... is the content to be removed. There are lot's of additional possibilities, like remove all until end/begin of string depending on a sequence. Ex.: var = "Hallo du Freak!" var=`echo ${var/ Freak}` echo $var Leads to: "Hallo du!" One disadvantage is that this way is by far NOT so complex like sed or awk. Only simple things can be done like this... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.