metacharacters separation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting metacharacters separation
# 1  
Old 01-15-2011
metacharacters separation

I have prepared a script to submit a string in a txt file.
However there are somethings that I have to check before submitting the string in the txt file.
One of those checks is to determine whether the string entered contains any metacharacters.
I have tried sth like;
Code:
echo "string" | grep -v [a-zA-Z0-9]
echo "string" | egrep -v .|,|!

however it doesn't work.
How can i check whether the string entered includes any metacharacters or not?

Last edited by Franklin52; 01-17-2011 at 04:23 AM.. Reason: Please use code tags
# 2  
Old 01-15-2011
Quote:
Originally Posted by ozum
I have prepared a script to submit a string in a txt file.
However there are somethings that I have to check before submitting the string in the txt file.
One of those checks is to determine whether the string entered contains any metacharacters.
I have tried sth like;
echo "string" | grep -v [a-zA-Z0-9]
echo "string" | egrep -v .|,|!
however it doesn't work.
How can i check whether the string entered includes any metacharacters or not?
Code:
case "$string" in
     *[!a-zA-Z0-9]*) echo "non alphnumeric" ;;
     *) echo OK ;;
esac

# 3  
Old 01-16-2011
thank you for the response however
this one didn't work since i 'm using a sentence as a string.
here is the response;

Code:
>more alphanumeric.sh
case "$1" in
     *[!a-zA-Z0-9]*) echo "non alphnumeric" ;;
     *) echo OK ;;
esac
>./alphanumeric.sh "this sentence doesn't contain any metacharacters"
non alphnumeric
>./alphanumeric.sh "this sentence contains * metacharacters"
non alphnumeric

###
also other than the alphanumerics, my sentence can also contain . or , or !
Can you help me with this?

Last edited by Franklin52; 01-17-2011 at 04:24 AM.. Reason: code tags
# 4  
Old 01-16-2011

Add whatever characters you want to allow to the pattern, e.g.:
Code:
case "$string" in
     *[!a-zA-Z0-9\ !]*) echo "not OK" ;;
     *) echo OK ;;
esac

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum up formatted numbers with comma separation

I need to sum up the values in field nr 5 in a data file that contains some file listing. The 5th field denotes the size of each file and following are some sample values. 1,775,947,633 4,738 7,300 16,610 15,279 0 0 I tried the following code in a shell script. awk '{sum+=$5} END{print... (4 Replies)
Discussion started by: krishmaths
4 Replies

2. Shell Programming and Scripting

How to determine column separation format?

Hi there, say I have a line with multiple columns but with different separation formats: spaces, tabs.. Is it possible to have AWK print the separation format between each column? (10 Replies)
Discussion started by: la2015
10 Replies

3. Shell Programming and Scripting

File Separation

Hi I have an XML File with default header($ lines of data) and default tail (Two Lines) and the body has occurrence of start<Folder> and ends with </Folder>. Now i want to split each occurrence i mean each start and end in to separate files with header and tail. For example: header line... (12 Replies)
Discussion started by: Nithin Kumar
12 Replies

4. UNIX for Dummies Questions & Answers

The ll command + metacharacters

Hello. I am learning how to use Unix through an online course. Unfortunately the text that we use isn't very good, so I could use some help with a pretty basic question. Use metacharacters and the ll command to list all filenames under the datafiles directory that contain a dot "." with the... (2 Replies)
Discussion started by: feverdream
2 Replies

5. Shell Programming and Scripting

Metacharacters analysis

:confused:Hi , Can someone please advise what is the meaning of metacharacters in below code? a_PROCESS=${0##*/} a_DPFX=${a_PROCESS%.*} a_LPFX="a_DPFX : $$ : " a_UPFX="Usage: $a_PROCESS" Regards, gehlnar (3 Replies)
Discussion started by: gehlnar
3 Replies

6. Shell Programming and Scripting

Unwanted field separation in awk

Hi everyone, My problem is strange, I cannot think of why this is happening. I have a set of data that looks like this: Although it does not look it, the fields are tab delimited. I have made sure of this, and awk does recognize them as such. However, it divides what I would expect... (2 Replies)
Discussion started by: ccox85
2 Replies

7. Shell Programming and Scripting

Joining three lines with comma separation

I have a file that looks like this: G. KRESSLAR 9618 W. APPALOOSA DRIVE SUN CITY, AZ 85373 SHIRLEY ALLEN 7272 W. VIA MONTOYA DRIVE GLENDALE, AZ 85310 LOUIS VALDEZ 244441 N. 86TH AVENUE PEORIA, AZ 85383 DONNA NEWBON 3231 W. DENTON #D PHOENIX, AZ 85017 SARAH WILSON 6534 W. PALO... (3 Replies)
Discussion started by: BCarlson
3 Replies

8. UNIX for Dummies Questions & Answers

Metacharacters

I want to display an asterisk to the screen as part of a string. I know how to use the Backslash to escape it's value. But how do I display it without showing the Backslash? (1 Reply)
Discussion started by: regencyabs
1 Replies

9. Shell Programming and Scripting

Using metacharacters in loops

Is there a way to use metacharacters in a loop or in an if. I want to allow a user to enter Y, y, Yes, yes, Yah, etc... in a loop I tried: read response while *" ] do........ and while *" ] do ......... this works for grep or egrep but not in loops Why?????? (4 Replies)
Discussion started by: jrdnoland1
4 Replies
Login or Register to Ask a Question