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
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.
# 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
$ 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__ |&"'
$