Reputation: 665
Hi I have a shell variable like this
input="/local/1/hadoop/MISDATA1/Risk_Analytics/blocker/risk/"
I want to replace the last part 'risk' to 'risk_unzip' like this
/local/1/hadoop/MISDATA1/Risk_Analytics/blocker/risk_unzip/
I tried like this
output="$( echo -e "$input" | tr 'risk' 'risk_unzip' )"
Not works for me. Any help would be appreciated.
Upvotes: 1
Views: 42
Reputation: 5591
Try with sed
like below:-
input="/local/1/hadoop/MISDATA1/Risk_Analytics/blocker/risk/"
input=$(echo "$input" | sed 's/risk/risk_unzip/g')
Upvotes: 1
Reputation: 241881
If you are using bash:
output=${input/risk/risk_input}
If you want it to work with any Posix shell (in which case, the bash tag is incorrect), but you know that risk
is the last component:
output=${input%risk/}risk_input/
Upvotes: 2
Reputation: 133650
Following may help you on same.
echo "$input" | awk -F"/" '$(NF-1)=="risk"{$(NF-1)="risk_unzip"} 1' OFS="/"
Upvotes: 0