- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Filtering for specific chars.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-30-2007 06:51 AM
тАО05-30-2007 06:51 AM
/bin/sh, shell script, asks for user input and reads user input. The current script allows the user to input ANY character for comments. These comments are then written to a file that gets built on the fly and saved as an XML file. Further, a "home grown" interpreter/file parsing utility takes this xml file and reads it into another application. Finally, this app EXPLODES if any of the following characters have been input, at the beginning, by the user....
*, @, #, $, % and &.
Does anyone out there have a good method for looking at the user input string to verify whether or not it contains the above forbidden characters?
For example, the user might input a string like:
The upper & lower limits are out-of-range.
The character "&" is the problem. I'd like to be able to simply loop back, clear the string, give the user an error message flagging the illegal character and have them resubmit the comment with only alpha chars. I don't need any looping, etc stuff, just a working method to sense the illegal chars.
Any ideas? Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-30-2007 07:15 AM
тАО05-30-2007 07:15 AM
Re: Filtering for specific chars.
This shell script shows one way:
cat .myfilter
#!/usr/bin/sh
while true
do
read LINE
echo ${LINE}|grep -q -e '\*' -e '\@' -e '\#' -e '\$' -e '\%' -e '\&'
[ $? = 0 ] && echo "REJECTED!" || echo "ok"
done
...run as ./myfilter
...and type sample lines with/without the characters you want to filter.
Regards!
...JRF...
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-30-2007 07:20 AM
тАО05-30-2007 07:20 AM
Re: Filtering for specific chars.
will return a 1 if one of the characters is found and 0 if not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-30-2007 08:40 AM
тАО05-30-2007 08:40 AM
Re: Filtering for specific chars.
That's the problem that I ran into... which is why I asked for other solutions.
I appreciate the input... any other suggestions would also be appreciated.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-30-2007 08:50 AM
тАО05-30-2007 08:50 AM
SolutionOoops, a bit careless, I was:
Quote the variable as:
# echo "${LINE}"|grep -q -e '\*' -e '\@' -e '\#' -e '\$' -e '\%' -e '\&'
# cat .myfilter
#!/usr/bin/sh
while true
do
read LINE
echo "${LINE}"|grep -q -e '\*' -e '\@' -e '\#' -e '\$' -e '\%' -e '\&'
[ $? = 0 ] && echo "REJECTED!" || echo "ok"
done
Regards!
...JRF...
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-30-2007 08:52 AM
тАО05-30-2007 08:52 AM
Re: Filtering for specific chars.
#!/usr/bin/sh -f
The '-f' turns OFF file name generation, which is what the '*' is doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-30-2007 02:00 PM
тАО05-30-2007 02:00 PM
Re: Filtering for specific chars.
Any reason you are using both types of quoting?
It would seem that you could just use fgrep so you wouldn't have to use \*. And the rest aren't special regexp(5) chars.
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2007 12:14 AM
тАО05-31-2007 12:14 AM
Re: Filtering for specific chars.
alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit
Use something like this:
### more code ###
read LINE
BADCHARS=$(echo "$LINE" | tr -d '[:alnum:]')
if [ ${#BADCHARS} -gt 0 ]
then
VIEWBAD=$(echo "$BADCHARS" | cat -v)
echo "Unacceptable characters: $VIEWBAD"
### more error handling ###
else
echo OK
fi
You can change the character class to [:alpha:] to eliminate numbers or other character classes may be combined with subsequent tr commands.
Bill Hassell, sysadmin
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2007 12:47 AM
тАО05-31-2007 12:47 AM
Re: Filtering for specific chars.
Dennis wrote:
> JRF: -e '\*' -e '\@' -e '\#' -e '\$' -e '\%' -e '\&'
Any reason you are using both types of quoting?
Yes, although for other than '\$' both types of quouting were over-kill and I used them only for consistency.
What I was avoiding was matching any newline as:
# echo "\n"|grep -q \$ && echo NOT_WANTED!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-15-2007 04:28 AM
тАО06-15-2007 04:28 AM