I want to create an awk script that, passed a URL, trims off the final section (everything after the last '/'
I've created the following in a file trim.awk:
---------------------------
BEGIN { FS="/"
new_var = "" }
{ for (count_var=1; count_var<NF; count_var++) {
new_var = $new_var$count_var
print count_var " - " $count_var " - " $new_var }
}
---------------------------
I'm calling it from the command line with:
echo "www.helloworld.com/this/is/a/test" | awk -f trim.awk
The results I get are far from what I expected:
1 -
www.helloworld.com -
www.helloworld.com/this/is/a/test
2 - this -
www.helloworld.com/this/is/a/test
3 - is -
www.helloworld.com/this/is/a/test
4 - a -
www.helloworld.com/this/is/a/test
In other words, my $new_var is returning the whole input string every time, regardless of what it's assigned to...
Any ideas? I presume I'm doing something basic wrong, but I've been looking at this for a whole day...
Dave