Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-19-2009
Registered User
 

Join Date: Jul 2008
Posts: 6
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:


Code:
echo "parentCategory = $parentCategory"
echo "parentCategoryFormatted = $parentCategoryFormatted"

numUrlsFoundInParentCategory=`grep -c "<Topic r:id=\"Top\/World\/Français\/" $inputFile`

echo "Hard-coded result = $numUrlsFoundInParentCategory"

numUrlsFoundInParentCategory=`grep -c \""<Topic r:id=\\\"$parentCategoryFormatted"\" $inputFile`

echo grep -c \""<Topic r:id=\\\"$parentCategoryFormatted"\" $inputFile

echo "Dynamic result = $numUrlsFoundInParentCategory"

It produces the output...

parentCategory = Top/World/Français/
parentCategoryFormatted = Top\/World\/Français\/
Hard-coded result = 22093
./dmozStats.sh: command substitution: line 44: unexpected EOF while looking for matching `"'
./dmozStats.sh: command substitution: line 45: syntax error: unexpected end of file
grep -c "<Topic r:id=\"Top\/World\/Français\/" content.rdf.u8.clean
Dynamic result =


I can't find out why the command using the variable won't work when it appears to look the same as the hard-coded version.

Thanks!
Sponsored Links
  #2 (permalink)  
Old 01-19-2009
Registered User
 

Join Date: Nov 2006
Location: UK
Posts: 190
I think that this is all to do with nested quotes and cascading backslashes!

Try setting the -x option in the script and see if the trace output helps.

Jerry
  #3 (permalink)  
Old 01-20-2009
MarkR's Avatar
Registered User
 

Join Date: Mar 2008
Location: West Wellow, England
Posts: 11
You seem to have gone a bit too far with the backslashes!

I'm assuming your input file looks a bit like this:


Code:
cat zzz.txt
<Topic r:id="Top/World/Français/
<Topic r:id="Top/World/Français/
dfgg
<Topic r:id="Top/World/Français/

If you can set your variable differently it should work:


Code:
parentCategoryFormatted="\"Top/World/Français/"
numUrlsFoundInParentCategory=`grep -c "<Topic r:id=$parentCategoryFormatted" zzz.txt`
echo "Dynamic result = $numUrlsFoundInParentCategory"
Dynamic result = 3

Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error to "find" a matching array element in a directory mkbaral Shell Programming and Scripting 1 09-30-2008 02:06 PM
"syntax error near unexpected token `fi' " GIC1986 Solaris 4 09-19-2008 01:17 PM
"unexpected end of file" when I´m use EOF inside block if ricardo.ludwig Shell Programming and Scripting 4 03-28-2008 03:45 PM
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 11:16 AM
"syntax error at line 21 :'done' unexpected." error message" ibroxy Shell Programming and Scripting 3 08-08-2007 07:45 AM



All times are GMT -4. The time now is 09:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0