Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to match for a string that contains "/"
I'm using nawk from within a bourne shell script.the nawk I'm using is:
nawk '$0 ~ /'$class_name*.class'$/ {print $0}'$class_name could contain a string like:
javax/activation/MimeTypestdin to nawk contains strings with forward slashes.
how do I construct a match in nawk where the string to match, and std, both contain "/"?
here's my error message from nawk:
nawk: syntax error at source line 1
context is
$0 ~ >>> /javax/activation/MimeType*. <<< class$/ {print $0, jar_name}
nawk: bailing out at source line 1I'm assuming nawk doesn't like the forward slashes.
Thanks in advance for your help and suggestions.
Tom

There're too many things to talk about. Study it yourself carefully.
#!/bin/ksh
class_name="javax/activation/MimeType[0-9a-zA-Z_]*.class"
echo "javax/activation/MimeTypeTEST.class" | nawk -v class_name_in="$class_name" '$0 ~ class_name_in {print $0}'
Output:
javax/activation/MimeTypeTEST.classNote: [:print:] and [:alnum:] don't work well on my Sun machine. So, I used [0-9a-zA-Z_]* instead.
Luke Chi

wow, Luke thanks so much, that worked great!
since for my script the class_name is a commandline option, it's easy to append the pattern "[0-9a-zA-Z_]*.class" to it.
Thanks again for your help.
Tom

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |