Protection and special characters

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Protection and special characters
# 1  
Old 11-05-2014
Protection and special characters

I am learning from the class how to protect the special characters and the script that I wrote here does not work when I am trying to pick up a single quote. It would complaint about parentheses problem. Please, someone could enlighten me.

Thanks in advance,

Scopiop

Input file
Code:
Hi, * ? [ ] ' " \ $ ; & ( ) | ^ < > new-line space tab

'echo <-$1500.**>; (update?) [y|n]
Putting a backslash in front of each special character is tedious and makes the line difficult to read:

echo \<-\$1500.\*\*\>\; \(update\?\) \[y\|n\]
*There is an easy way to quote a large group of characters. 
Put a single quote ( ') at the beginning and at the end of the string:


script: read in the input file and grep the beginning of the ('|>) sentence with a single quote or greater sign.


Code:
# USE egrep to SEARCH IT FOR A REGEX (regular expression)
# PATTERN WHICH ALSO CONTAINS SPECIALS.

# file name is "new_spci\!" then create a SYMBOLIC link to a new name new__ |&

# Using the quote in a "new__ |&" to protect the filename

ln -sF new_speci\\\! "new__ |&"

ls

# "^ : indicates the begining of the search"
# " (..|..) begin of the search with or statement as using a PIPE"
# " The following dot . are character and + is conntinue more dots"
# " (:|]) search for ':' and ']' at the end of the sentences "
# " $ is the end of the search "
# " ' single quote is for closing' the search"
# then file name 

#egrep '^(e|t).+(:|])$' "new__ |&"

# Must have a slash before ?, other wise will get an error
egrep '^(>|').+(:|\?)$' "new__ |&"

output
Code:
$ InClassPracice1104
ln: creating symbolic link `new__ |&': File exists
InClassPracice1104  Linklsnln.sh  new_speci\!	PrepareHW1	tpham44_HW1.sh
InClassPratice1028  new__ |&	  Practice1031	tpham44_hw1.sh
 line 27: syntax error near unexpected token `)'
 line 27: `egrep '^(>|').+(:|\?)$' "new__ |&"'
$

# 2  
Old 11-05-2014
Firstly, welcome to the forums. There is actually a template for homework problems to include course information.

Rules for Homework

The single quote is special. The only thing that needs quoted (in regards to the shell) inside of it is itself. And it's a pain because actually you can't. You must exit the quote, insert an escaped single-quote, and begin a quote again.

For example: 'left'\''right'
# 3  
Old 11-05-2014
Thanks, it works....
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 remove special characters?

Hi Gurus, I have file which contains some unicode charachator like "ü". I want to replace it with some charactors. I searched in internet and got command sed "s/ü/-/g", but I don't know how to type ü in unix command line. Please help me for this one. Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies

2. Shell Programming and Scripting

File containing special characters

Hello All, I am facing challenges in order to transfer a file from windows to unix box,the file contains a special character '×' ,now when I am transferring the file from windows to unix that special character converted to something else like 'Ã' ,another thing I have noticed that the hardware is... (1 Reply)
Discussion started by: prarat
1 Replies

3. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

4. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

5. Shell Programming and Scripting

Escaping special characters

I'm attempting a little hack to get grep to highlight (change foreground color to red) a found string. Assuming a target file "test" consisting of the word "albert": My executable "algrep" consists of this: grep $1 $2 | sed "s/$1/\\\033 And when run: algrep al test Produces this:... (2 Replies)
Discussion started by: tiggyboo
2 Replies

6. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

7. Shell Programming and Scripting

Special characters

When I open a file in vi, I see the following characters: \302\240 Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file. I am doing the following: tr -d '\302\240' ---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)
Discussion started by: sid1982
1 Replies

8. UNIX for Dummies Questions & Answers

Substitue 'Special Characters' in VI

Hi All, I am using LATEX and need to delete all the lines in a file matching: \begin{work} I know there are several ways to do this, but I am trying to do it with the substitute command in VI. The problem is I can't get substitute to recognize the character '\'! How do I do it? ... (7 Replies)
Discussion started by: ScKaSx
7 Replies

9. UNIX for Dummies Questions & Answers

Quoting of special characters

Hello, I am getting very confused as to where should i quote special/metacharacters in shell. Sometimes i write * directly and it works, othertimes i have to do "*". Same is the case with other special characters like /,\,.,$,etc. Can somebody give me link to somewhere where i can found... (1 Reply)
Discussion started by: vibhor_agarwali
1 Replies

10. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question