Solved how to change a / to a _

October 12, 2012 at 07:18:36
Specs: Sun OS 5.8 Generic
I have to create a directory name from a filename. For example /export/home/usr/bin. I want to create another variable which will contain export_home_usr_bin. I am getting in a list of directories to tar and gzip but I want the name to use the created variable when I build the back of that using tar and gzip.

See More: how to change a / to a _

Report •

#1
October 12, 2012 at 08:16:00
✔ Best Answer
You are asking to change the 2 to n slash to an underscore. The second pipe handles the first slash. I deleted it, but you could change it to something else:

#!/bin/ksh

filename="/export/home/usr/bin"

fn=$(echo $filename|sed 's&/&_&g'|sed 's&_&&')
echo $fn


Report •
Related Solutions


Ask Question