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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a string to a pathname 2

Status
Not open for further replies.

630111

MIS
Oct 30, 2001
127
US
Greetings!

I've had a request to convert something like this

00054WNGB398977DS

to this \00054\WNGB3\98977.DS

I suppose it would be easy enough to do it by hand, but I have to do it 2625 times! What utility would I use, and what syntax?

I'm guessing every string is consistent. For sure, there is a dot before the last two characters. I'm guessing it's a pattern like backslash, go forward five characters, insert a backslash, go forward five characters, insert a backslash, go forward 5 characters, insert a dot.

Thanks!
630111
 
echo '00054WNGB398977DS' | nawk -f 630111.awk

here's the 630111.awk
Code:
BEGIN {
  step=5
  SLASH="\\"
  DOT="."
}
{
  new=""
  len=length($0)
  for(i=1; i < len; i=i+step) {
     new= ((i==1) ? "" : new ((i+step > len) ? DOT : SLASH) ) substr($0,i, step);
  }
  print new
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
echo "00054WNGB398977DS" | sed 's!\(.....\)!\\\1!g;s!\(..\)$!.\1!'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
or better yet:
Code:
echo '00054WNGB398977DS' | sed 's!.\{5\}!&\\!g;s!\\\([^\]*\)$!.\1!'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top