2

within script the attempt here is to remove the : and then revert the / to \ within the print out

currently I have to display the linux path: The home directory is located here: rtp1-filer-ns:/homedir-private/private007/user

and would like to reformat as for my users ease Windows path to home directory: \rtp1-filer-ns\homedir-private\private007\user

currently this part of the script is as follows

 echo "The shell is: `ypmatch $EndUser passwd | awk -F\: '{ print $7 }'`" echo "" echo "The home directory is located here:" ypmatch $EndUser auto_home echo "" echo "Windows path to home directory:" echo "\\\\`ypmatch $EndUser auto_home | awk -F':' '{print $1}'`\\$EndUser" 

gives me the print out of :

 The home directory is located here: rtp1-filer-ns:/homedir-private/private007/user Windows path to home directory: \\rtp1-filer-ns\user 

assuming i can use sed /awk something of the sorts , open for suggestions $EndUser is a defined var

    1 Answer 1

    1

    With bash

    First approach - use parameter substitution

    #use command substitution to set command output into variable var var=$(ypmatch $EndUser auto_home) #strip out the first : var=${var/:} #replace all instances of / with \ var=${var//\//\\} echo $var rtp1-filer-ns\homedir-private\private007\user 

    Second approach - use arrays

    # Set path components into array frags IFS=/ read -a frags < <(ypmatch $EndUser auto_home) # Strip ":" off rtp1-filer-ns frags[0]="${frags[0]%:}" # Set IFS to \ to print frags \-separated echo "$(IFS=\\ ;printf '%s\n' "${frags[*]}";)" rtp1-filer-ns\homedir-private\private007\user 
    1
    • Awesome ! works like a charm ! Thanks Much!
      – Tim M.
      CommentedMar 4, 2016 at 22:20

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.