Simple C Shell script is not so simple
Imagine the following program in C Shell. What should I put in place of the question marks to assign the variables a, b, c, d or any other variables like them that may show up to the last number after the last backslash.
set a = "a/b/c/d/1/2/3" set b = "e/r/r/4" set c = "dew/gr/34/op3/22" set d = "33/22/11/1?" . . . ?????????????????????? So, I want to set the variables a, b, c, d to 3, 4, 22, and 1?. I tried using awk, but it was a disaster. HELP!!! |
I would use bourne shell, C shell stinks when writing scripts. Use awk to find the number of slashes in the line, then use cut to cut out the last field. You will need to set the field seperator for awk. I tried it quickly here and awk didn't like the '/' as a delimiter. You can probably hack at it a bit to make it work.
Code:
FIELDS=`echo $A | awk ' { FS = "/"; print NF } '` |
thanks
Thanks for the advice. I'll try it out.
-Robert |
All times are GMT -5. The time now is 08:07 AM. |