pattern matching w/ unexpected characters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers pattern matching w/ unexpected characters
# 1  
Old 06-22-2009
pattern matching w/ unexpected characters

how do i check if the first character is a parenthese in pattern matching?

if [[ $a == (* ]] obviously doesnt work. How do I use it to compare so it doesnt try to use it to group.
# 2  
Old 06-22-2009
one way to skin that cat:
Code:
#!/bin/ksh
set -x

a='(abc'

if [[ "${a%%${a##?}}" = '(' ]]; then
   echo '( - first char'
fi

# 3  
Old 06-22-2009
what about if the string assigned to the variable isn't a constant length? i.e. the string assigned to that variable changes.
# 4  
Old 06-22-2009
Quote:
Originally Posted by questionasker
what about if the string assigned to the variable isn't a constant length? i.e. the string assigned to that variable changes.
it'd not bite if you try.
# 5  
Old 06-22-2009
Quote:
Originally Posted by vgersh99
it'd not bite if you try.

i'd love to, im just at home Smilie Something for tomorrow i suppose.
# 6  
Old 06-22-2009
Code:
# a="(dsfsf"
# case $a in \(* ) echo ok;; esac
ok

awk
Code:
echo $a | awk '{print /^\(/?"ok":"not ok"}'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In awk: unexpected EOF while looking for matching `"'

I am trying to get grep with awk command into variable. But facing error. Could someone pls help. $ cat test_file DEPLOYMENT="abc" # com cluster="bcn" $ grep DEPLOYMENT test_file | awk -F "\"" '{ print $2 }' abc $ a=`echo "grep DEPLOYMENT test_file | awk -F \"\\\"\" '{ print $2 }'"` ;... (6 Replies)
Discussion started by: Manasa Pradeep
6 Replies

2. Shell Programming and Scripting

Unexpected EOF while looking for matching `'' when ran from a cron job

Since cPanel does not support deleting emails older then X amount of days I am using the following on a Cron Job. find -P /home/user/mail/domain/ -mindepth 2 -mtime '+366' -type f -printf '"%p"\n' | grep -v '/Important' | grep -v '/.Important' | xargs -I {} rm -r "{}" Executing it via SSH... (4 Replies)
Discussion started by: tiagom
4 Replies

3. Shell Programming and Scripting

Unexpected EOF while loooking for matching '"

Hi everyone, I'm really new in shell scripting and having trouble resolving this error. Can someone please tell me why I'm getting these errors? Error Message: ./test.sh: line 50: unexpected EOF while looking for matching `'' ./test.sh: line 53: syntax error: unexpected end of file ... (4 Replies)
Discussion started by: simonirang
4 Replies

4. Shell Programming and Scripting

Help to resolve unexpected EOF while looking for matching `"' error

Hi, can someone kindly look into my copy script and figure out why am i getting a "unexpected EOF while looking for matching `"' error message #!/bin/ksh -x cd /home/goldenga/test/flag37 if ; then rm copied.ok cd /home/goldenga/test Upper=`ls -t|grep 'qw*'|cut -d "w" -f 2|head... (4 Replies)
Discussion started by: NDalal007
4 Replies

5. Shell Programming and Scripting

Matching a pattern 250 characters up and down stream

hii all i have a file a which contains some thing like this strand smthg position + yyx 3020 - yyw 10,000 now i have another file (file2) which contains the data starting from 1 to n positions i want to refer first file if + ... (4 Replies)
Discussion started by: anurupa777
4 Replies

6. Shell Programming and Scripting

Unexpected EOF while looking for matching `"'

I have a piece of Linux script. It tells me some syntax error. I couldn't find it. Please help me to identify them. Thanks. The code looks like this: export ORACLE_SID=MYDB export SPW=`cat /opt/oracle/scripts/.sys_pw_$ORACLE_SID` export check_arch=`sqlplus -s << EOF / as sysdba... (7 Replies)
Discussion started by: duke0001
7 Replies

7. Shell Programming and Scripting

Matching a pattern between two characters (sed)

Hi there, I have a file with lines like these: 0105:ffff0000:001b:01f4:25:434 0299:ffff0000:0009:01f4:2:319 02d2:ffff0000:000e:01f4:2:507 The above values are split up using ":" characters. I would like capture each value, no matter what length. Take for example the first line... (8 Replies)
Discussion started by: MastaG
8 Replies

8. Shell Programming and Scripting

line 85: unexpected EOF while looking for matching `"'

hello everyone...im having this problem with unexpected EOF with line 85 which is..i cant see whats wrong with it..can any1 plz help me out. read -p "$p1 please enter the number of tries you wish to have:" lifeline function main() { guessnum=0 read -p "Please... (6 Replies)
Discussion started by: Freakhan
6 Replies

9. Shell Programming and Scripting

Unexpected characters

Hi, I have got this shell script that writes certain data to a file after reading a few things from another file. while read line do name=$line echo "perl $line" >> file.sh done < a.properties Now the problem is that when I am running it in one UNIX server (SunOS 5.8) it... (4 Replies)
Discussion started by: King Nothing
4 Replies

10. Shell Programming and Scripting

Unexpected EOF while looking for matching `"'

Hi everyone, I am trying to search for a string in a file that is partly made up of a variable. Here's the code: echo "parentCategory = $parentCategory" echo "parentCategoryFormatted = $parentCategoryFormatted" numUrlsFoundInParentCategory=`grep -c "<Topic r:id=\"Top\/World\/Français\/"... (2 Replies)
Discussion started by: BlueberryPickle
2 Replies
Login or Register to Ask a Question