Special Character Check in Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Special Character Check in Shell script
# 1  
Old 03-24-2006
Special Character Check in Shell script

Hi,

I'm currently working on a project that requires parsing xml file. One of the field in the xml is shown below (don't remember exactly):
<variable="ITEM">12345678</variable>
I coded my script keeping in mind that the value denoted in bold will always be a number. After getting just the number I have to fire a PL/SQL procedure from the script itself and get the data, and update the existing xml file with some new fields that i received by firing the procedure.
But now the requirements have changed and now the users wants a check for special characters on the item shown as bold.
eg: We refer the text in bold as Item Number. So if the following Item Number is found 1234%1234, in this case my script should remove only the % sign and put together the rest of the numbers and form one number.
Now the problem is that there are 36 such special characters on the keyboard.
I tried using ITEMNUMBER=echo $ITEMNUMBER|sed 's/%//g'
But this would work for only one scenario. If i follow this case, I have to write 36 such statements and that would inturn reduce the performance of the script.
PS: Keep in mind the following special charaters in unix 1. & - &amp;
2. < - &lt;
3. > - &gt;
4. " - &quot;
5. ' - '

Hoping for some help

Thanks in advance.

MK
# 2  
Old 03-24-2006
mradul_kaushik,

Use something like this.
Code:
sed -e 's/[[:alpha:]]\|[[:punct:]]//g'

This will remove any alpha and punctuation char's.

Hope it helps,

MPH
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to understand special character for line reading in bash shell?

I am still learning shell scripting. Recently I see a function for read configuration. But some of special character make me confused. I checked online to find answer. It was not successful. I post the code here to consult with expert or guru to get better understanding on these special characters... (3 Replies)
Discussion started by: duke0001
3 Replies

2. Shell Programming and Scripting

Shell script question in special character

when I execute the unix commands its works normally in the 1st part. When I the tried the same in shell scripting the directory is not displayed in 2nd part example. please let me know what needs to be done. Unix : client=~zsvdbs echo $client /shome/zsvhome/zsvdbs Using... (3 Replies)
Discussion started by: keerthi2016
3 Replies

3. Shell Programming and Scripting

Trigger email from script if the Special Character replacement is successfull

Hello Gurus, I have a script developed... #!/bin/bash #--------------------------------------------------------------------- # This pScript will remove/replace the special characters fromfiles #--------------------------------------------------------------------- trxdate="`date... (1 Reply)
Discussion started by: nanduedi
1 Replies

4. Shell Programming and Scripting

Use arrow touch in a script shell without special character

Hello, I have a problem when i execute the script underneath. If i tape azerty 123 and i use the arrow touch, in the file /tmp/test i have the caracter #!/usr/bin/ksh clear echo "Taper l adresse IP de la partition a creer :" tput cup 1 48 read Adress echo $Adress echo "${Adress}" >>... (0 Replies)
Discussion started by: khalidou13
0 Replies

5. Shell Programming and Scripting

How to check for special character in a value

Hi, I have a variable and to it always alphanumeric value will be assigned. If the value has any special characters in it then in the if statement it should exit like below if (value has any speacial character) then exit else .... fi can any one suggest how to acheive this? (4 Replies)
Discussion started by: lavnayas
4 Replies

6. Shell Programming and Scripting

Deleteing one character after an special character

I have below line in a unix file, I want to delete one character after "Â". 20091020.Non-Agency CMO Daily Trade Recap Â~V Hybrids The result should be : 20091020.Non-Agency CMO Daily Trade Recap  Hybrids i dont want to use "~V" anywhere in the sed command or any other command, just remove... (1 Reply)
Discussion started by: mohsin.quazi
1 Replies

7. Shell Programming and Scripting

Perl Script Syntax to Extract Everything After Special Character

Hi, I am writing a Perl script that reads in many lines, if a line meets the criteria I want to edit, it. For example, the script will return the following example line... test=abc123 All I want to do is strip off the "test=" and just be left with the abc123. In my script I can easily... (3 Replies)
Discussion started by: edrichard
3 Replies

8. Shell Programming and Scripting

Using Awk script to check length of a character

Hi All , I am trying to build a script using awk that checks columns of the înput file and displays message if the column length exceeds 35 char. i have tried the below code but it does not work properly (2 Replies)
Discussion started by: amit1_x
2 Replies

9. Shell Programming and Scripting

bash script to check the first character in string

Hello would appreciate if somebody can post a bash script that checks if the first character of the given string is equal to, say, "a" thnx in advance (2 Replies)
Discussion started by: ole111
2 Replies

10. Shell Programming and Scripting

Check for special characters in a script

Hi All, In my shell script, i'm checking the date input against few constraints. It should be of YYYYMMDD format and the script should prompt the user with error message, if less than 8 digits are present or input contains special characters (*,&,%,^,$ ...etc). The script i'm using is given... (7 Replies)
Discussion started by: sumesh.abraham
7 Replies
Login or Register to Ask a Question