Finding Special Character in Vi


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding Special Character in Vi
# 8  
Old 07-10-2013
Thanks for the contribution Smilie
# 9  
Old 07-10-2013
Quote:
Originally Posted by bobbygsk
After googling, I found out the following

Vi
Code:
/[^0-9a-zA-Z,_&-\/<>?=\"\':\\\. *]

... ... ...
Assuming that you're using a common US keyboard, the above expression will find several characters that are on the keyboard including, but not limited to {, }, |, [, and ] and you have a few unneeded backslashes. The following is a more complete vi search command:
Code:
/[^][[:space:]0-9a-zA-Z~!@#$%^&*()_+`={}|\\;':"<>?,./-]

Using the above search command on the output from the OS X command man 7 ascii only matches backspace characters. If you would also like to skip backspace and other control characters, you could use:
Code:
/[^][[:space:][:cntrl:]0-9a-zA-Z~!@#$%^&*()_+`={}|\\;':"<>?,./-]

The order of most of these characters doesn't matter, but the first three characters in this expression have to be [^] to start a non-matching expression that excludes ] and the - needs to be the last character before the closing ] to exclude the minus sign. (Your expression seems to have excluded - as an accident because in ASCII the range expression &-\/ (or equivalently &-/) in a non-matching expression excludes &, ', (, ), *, +, ,, -, ., and / and you also exclude several of these characters individually.) Of course, the [:space:] and [:cntrl:] have to remain as these sequences in order, but they can appear anywhere within the bracket expression.

Last edited by Don Cragun; 07-10-2013 at 07:27 PM.. Reason: Remove extraneous "1" from 1st search
These 3 Users Gave Thanks to Don Cragun For This Post:
# 10  
Old 07-10-2013
@Don Cragun..
Slightly modified your code.
Added escape character for "`" and worked.

Code:
 grep -n "[^][[:space:]0-9a-zA-Z~!@#$%^&*()_+\`1={}|\\;':\"<>?,./-]"  filename


Last edited by bobbygsk; 07-10-2013 at 05:45 PM..
# 11  
Old 07-10-2013
You search for negative range, like not tab plus not space through tilde: [^^I -~]
^I is tab 0x09 and ~ is 0x7E, so type that as [ ^ tab space - ~ ]

You can add any other specials that are OK in your context, like form feed ^L, carriage return ^M and backspace ^H. If they do not show on your screen, look at the line with ex command l: :.l

Last edited by DGPickett; 07-16-2013 at 04:59 PM.. Reason: Explain the tab more carefully.
# 12  
Old 07-10-2013
Quote:
Originally Posted by bobbygsk
@Don Cragun..
Slightly modified your code.
Added escape character for "`" and worked.

Code:
 grep -n "[^][[:space:]0-9a-zA-Z~!@#$%^&*()_+\`1={}|\\;':\"<>?,./-]"  filename

Yes. The search pattern I gave was just the one that works for vi. When you are passing the expression as an argument through a shell to grep (or some other utility) you have another level of quoting to worry about. With some shells you have to escape the backquote to avoid it being treated as the start of a command substitution inside a double quoted string. In other shells, that backslash wouldn't matter. With some shells, you might also have to escape the dollar sign. Note also that the "1" I marked in red above was a typo on my part. It won't hurt anything, but it isn't needed. I have also corrected it in my earlier message.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Special character $$

Hi, on ksh What does the following do? grep -v "toolbox" $home_oracle/.profile >$home_oracle/.profile.$$ Thanks. Please use CODE tags as required by forum rules! (3 Replies)
Discussion started by: big123456
3 Replies

2. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

3. Shell Programming and Scripting

Escape special character

Hi, How to use * in call to pl/sql block from shell script? The line "select * from" is causing all files and directiores to show up in email notification but if I give all column names then it works, Please let me know how to use '*' instead of giving all column names, in other wirds how to... (2 Replies)
Discussion started by: sandy162
2 Replies

4. Shell Programming and Scripting

Vi special character

When editing a file, vi displays a special character as ^L. Can you tell me the escaped character to be used in awk? And can that escaped character be used in a regexp in both sed and awk? (7 Replies)
Discussion started by: dmesserly
7 Replies

5. Shell Programming and Scripting

Decimal value for special character

I am seeing an special character in my file when i do the cat filename | od-bc I see a value of 376 for that special character. I would like to find the decimal value for the character. For example the decimal value for ctrl-Y is char(25). Appreciate help on this. (11 Replies)
Discussion started by: pinnacle
11 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

Special character \

Hi, In the shell script, i need to remove the special charater "\" with "\\". For example, i need to replace "D:\FXT\ABC.TXT" with "D:\\FXT\\ABC.TXT". However, when trying to do something like , i get the below error :- -->echo "D:\FXT\ABC.TXT" | sed -e 's#\#\\#g' sed: 0602-404 Function... (7 Replies)
Discussion started by: amit_arora
7 Replies

8. UNIX for Advanced & Expert Users

grep in special character

All, I am trying to grep "-----" from a test when i use this i am getting the below error. What is the reason for this ?????... How can i over come this ##) echo "----------------- test_sys_job -----------------" | grep "-----------------" grep: illegal option -- - grep: illegal... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

9. Shell Programming and Scripting

special character

Hi, I am trying to unload file from a database. Which contains few lines with the character below. Rest of the data was unloaded appropriately. a) What does this below character means? b) How can i remove it, I already have sed '/^$/d' c) Will this effect the file by any means... (4 Replies)
Discussion started by: tostay2003
4 Replies

10. Programming

special character ?

hey there im a bit stuck on executing commands that include the special character '?'. can someone recommend a way on how i would be able to execute it?? i thought the glob function could be useful (still mite be) but upon entering the command 'ls pars?' it listed all the files in the... (1 Reply)
Discussion started by: mile1982
1 Replies
Login or Register to Ask a Question