Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk matching::

Status
Not open for further replies.

PSD

Instructor
Apr 25, 2000
392
0
0
GB
Hi all,

The awk statement below nearly works as I want it to. That is it removes :: if it is on the end or beginning of the PATH variable, but :: anywhere else is not removed - however ::: is. So it is nearly there. Any awk experts able to shed light light on getting the :: removed rather than the ::: as it does now?

awk ' {
if(match($0,"^[\t ]*(set)*[\t ]*PATH[\t ]*=") != 0){
gsub("PATH[\t ]*=[\t ]*\\::","PATH=");
gsub("PATH[\t ]*=[\t ]*\"\\::","PATH=");
gsub(":\\::",":");
gsub(":\\:\"$","");
gsub(":\\:$","");
print $0;
}
else {
print $0;
}
}' ${1} > ${1}.work
mv ${1}.work ${1}
 
How about this?:
Code:
ThePATH=$1
echo $ThePATH|awk -F[:] '{for(i=1;i<=NF;++i){p=$i;if( p != "" ){op=op c p;c=":"}}} END {print op;}'
[3eyes]




----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top