/home/system/app/WebAgent1500/jre/bin/Java
This directory is how to extract the/home/system/app/WebAgent1500/, remove after 3 columns (jre/bin/Java), after only 3 column is invariable, the directory path in front of is will be, a great god give advice or comments, please
CodePudding user response:
Can't directly replace with sed?
CodePudding user response:
reference 1st floor agpintel response: directly replace with sed? Yes, already can replace with sed CodePudding user response:
/root @ yangzhen ~ # echo $STR | awk 'BEGIN {FS="/"} {print "/" $2 "/" $3 "/" $4 "/" $5 "/"}' /home/system/app/WebAgent1500/ CodePudding user response:
/root @ yangzhen ~ # STR="/home/system/app/WebAgent1500/jre/bin/Java" /root @ yangzhen ~ # echo $STR | sed 's/jre \ bin \/Java//g' /home/system/app/WebAgent1500/ CodePudding user response:
Echo "/home/system/app/WebAgent1500/jre/bin/Java" | awk -f "/" '{print "/" $2 "/" $3 "/" $4 "/" $5 "/"}' CodePudding user response:
Awk methods: Echo "/home/system/app/WebAgent1500/jre/bin/Java" | awk -f "/" '{print "/" $2 "/" $3 "/" $4 "/" $5 "/"}' After the sed to reference methods: Echo "/home/system/app/WebAgent1500/jre/bin/Java" | sed - r "s # (. *) jre. * # # \ 1 g" CodePudding user response:
reference 4 floor jasonyang69 response: /root @ yangzhen ~ # STR="/home/system/app/WebAgent1500/jre/bin/Java" /root @ yangzhen ~ # echo $STR | sed 's/jre \ bin \/Java//g' /home/system/app/WebAgent1500/ Thank you, I am using is also this article CodePudding user response:
Look at with this? Echo "/home/system/app/WebAgent1500/jre/bin/Java" | awk '{gsub (/\ jre \ bin \/Java/, "", $0); Print $0} '