Remove box like special character from end of string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove box like special character from end of string
# 8  
Old 02-02-2009
Quote:
Originally Posted by Qwerty123
Hi,

My requirement is that I store this string in suppose say $string...and compare it with a parameter that is input say $param ...
like

if [ $string = $param ]
then
echo 'True'
else
echo 'False'
fi

This $string is part of header (i.e another big string) which can be treated as a record (line) and this $string appears at the end of line. I fetch it based on positions...for ex: 30 to 60. In case the $string is of length 10 only, 11th character i.e, at position 41 there'll be this box like character (since I'm fetching 30 to 60 into $string). This character doesn't get trimmed. And since this box like character is present my comparision returns 'False' even when it's 'True'.

I have tried things like

string=`echo $string|tr -d '\n'`
and \t, \r, \222,\221---Ascii equivalents...and all that and then thought its not Ascii at all.

Still I couldn't solve this. Please helpSmilie
Well, read the file using:

Code:
sed -e 's/[^ -~]//g'

For sure, that'll remove the non-ascii boxes.
Then your comparisons will work.
# 9  
Old 02-02-2009
If you would like to send the 'string' (a variable) to the 'sed' you could use pipe from echo:
Code:
echo "$string"|sed -e 's/[^ -~]//g'

(although I am not sure what that sed-substitution does.)
# 10  
Old 02-02-2009
Quote:
Originally Posted by alex_5161
If you would like to send the 'string' (a variable) to the 'sed' you could use pipe from echo:
Code:
echo "$string"|sed -e 's/[^ -~]//g'

(although I am not sure what that sed-substitution does.)
the sed removes everything not in the range from blank to tilde.

blank is the first ASCII printable.... tilde is the last ASCII printable,
numerically speaking.
# 11  
Old 02-02-2009
I see, range from space to tilda. Thanks!
But what '^' is doing there?
I think there is no reason to specify the 'beginning of string'. Or there is some?
# 12  
Old 02-02-2009
Quote:
Originally Posted by alex_5161
I see, range from space to tilda. Thanks!
But what '^' is doing there?
I think there is no reason to specify the 'beginning of string'. Or there is some?
'man regexp'
Code:
     1.4   A non-empty string of characters  enclosed  in  square
           brackets  ([])  is a one-character RE that matches any
           one character in that string. If, however,  the  first
           character  of the string is a circumflex (^), the one-
           character RE matches any character except new-line and
           the remaining characters in the string. The ^ has this
           special meaning only if it occurs first in the string.
           The  minus (-) may be used to indicate a range of con-
           secutive characters; for example, [0-9] is  equivalent
           to  [0123456789].  The - loses this special meaning if
           it occurs first (after an initial ^, if any)  or  last
           in  the  string. The right square bracket (]) does not
           terminate such a string when it is the first character
           within  it  (after an initial ^, if any); for example,
           []a-f] matches either a right square  bracket  (])  or
           one  of  the  ASCII letters a through f inclusive. The
           four characters listed in 1.2.a above stand for  them-
           selves within such a string of characters.

# 13  
Old 02-02-2009
Quote:
Originally Posted by alex_5161
I see, range from space to tilda. Thanks!
But what '^' is doing there?
I think there is no reason to specify the 'beginning of string'. Or there is some?

When tilde is the first character inside of brackets,
it means "NOT in this range".
# 14  
Old 02-02-2009
Oh!! Right! - it is negotiation in brackets!
Sure!
Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove blank space and insert special character

Hi Folks, I have a huge data of the below format abc #apple 1200 06/23 ghj #orange 1500 06/27 uyt #banana 2300 05/13 efg #vegetable 0700 04/16 After first 3 letters, i have 9 spaces and after fruit there are no specific fixed space, but it varies... (4 Replies)
Discussion started by: jayadanabalan
4 Replies

2. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

3. Shell Programming and Scripting

Remove some special ascii character

Hello I have this special caracter after retreving rows from sql server: "....spasses: • Entrem al valort 6050108002811 • El donem..." I would like a sed command to remove it..or just know it's ascii code in order to replace it into my sql sentence.. Hope some one knows how to do that.... (7 Replies)
Discussion started by: ldiaz2106
7 Replies

4. Shell Programming and Scripting

Remove 3rd character from the end of a random-length string

Hi, I hope someone can share there scripting fu on my problem, I would like to delete the 3rd character from a random length of string starting from the end Example Output Hope you can help me.. Thanks in advance.. (3 Replies)
Discussion started by: jao_madn
3 Replies

5. Shell Programming and Scripting

Remove special character ($) from file names

Hello I've searched here and on the 'net for examples of a script or command line function that will remove the $ character from all file names only that can be done within the directory that contains the file names - which are all html files. ie, I have a directory that contains html files... (6 Replies)
Discussion started by: competitions
6 Replies

6. Shell Programming and Scripting

remove special character from a specific column

Hello , i have a text file like this : A123 c12AB c32DD aaaa B123 23DS 12QW bbbb C123 2GR 3RG cccccc i want to remove the numbers from second and third column only. i tried this : perl -pe 's///g' file.txt > newfile.txt but it will remove the number from... (7 Replies)
Discussion started by: shelladdict
7 Replies

7. Shell Programming and Scripting

Remove special char from end of the file

Hi I am working on a bash script and would know how to use cut or sed to remove (F/.M/d h) from a text file. Before 1 text to save (F/.M/d h) after 1 text to save Thanks in advance (5 Replies)
Discussion started by: pelle
5 Replies

8. Shell Programming and Scripting

remove special character from a textfile

Can any one plse help me writing shell script to removing some special character pattern (like / > -------, / > / > ------- etc....as shown below) from the text file ASAP. / > ------- <tag-normalization tag-name="EXECSERVPRODUCT" read-only="false" part="body"> ... (3 Replies)
Discussion started by: bkc
3 Replies

9. Shell Programming and Scripting

Adding a special character at the end of the line

I used following to add * at the end of the line in file1. It adds * at the end but has a space before it for some lines but some other lines it adds exactly after the last character. How do I take out the space ? sed 's/$/*/' file1 > file2 example: contents of file1 : ... (2 Replies)
Discussion started by: pitagi
2 Replies
Login or Register to Ask a Question