![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bourne Shell: Special characters Input Prevention | totziens | Shell Programming and Scripting | 37 | 04-23-2008 04:05 AM |
| Searching for escape characters | timcs | Shell Programming and Scripting | 8 | 05-25-2007 06:29 AM |
| Check for special characters in a script | sumesh.abraham | Shell Programming and Scripting | 7 | 12-18-2006 09:15 AM |
| escape characters.. | sharsin2001 | Shell Programming and Scripting | 9 | 11-06-2006 10:52 AM |
| Can't stop shell interpreting special characters | Doug97 | Shell Programming and Scripting | 2 | 11-23-2005 09:41 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Need help to escape special characters in Korn shell script
Hi,
I would like to display the following message from my shell (Korn) script Copy "old_file.txt" to "new_file.txt" My code looks as follows print "Copy "old_file.txt" to "new_file.txt"" However, when I execute the script, I get the following output Copy old_file.txt to new_file.txt Can somebody please help me with the syntax to escape the double quotes (") ? Thanks in advance. rogers42 |
|
||||
|
Hi,
I also need some quoting help. I tracked my problem down in a simple example. I have a grep that is working if typed at the shell prompt (it is important for me to have a space in the character class): Code:
grep -E '[a-zA-Z ]{30}:' myFile
Code:
#!/bin/ksh
typeset pattern='[a-zA-Z ]{30}:'
echo "Command to be executed: grep -E $pattern myFile"
grep -E $pattern myFile
grep: RE error in '[a-zA-Z [ ] imbalance or syntax error I googled/searched here for the error and for quoting or inserting something else which recognizes a space character, but with no success yet. Also I tried various quotings in runMe, like "'[a-zA-Z ]{30}:'" or "\"[a-zA-Z ]{30}:\"" or quoting the space character like "[a-zA-Z ]{30}:" but all lead to the same error message. Seems like it is breaking at the space? Curious for me: If I execute the script and copy the line which is printed by the 'echo' statement and paste this line at the command prompt, that works! It just doesn't work within the script... Maybe this not the adequate topic, because its more a grep issue than a quoting issue. If so, please be patient with me ![]() FYI: I'm relatively new to unix. In 'myFile', I want to (simplified for this issue) match lines, that have the first 30 characters being (a letter or a space), followed by a colon. I've aliased grep to /usr/xpg4/bin/grep (and also tried /usr/xpg4/bin/grep manually without alias). thanks in advance for any hints, Thinkpositiv Last edited by Thinkpositiv; 04-29-2008 at 10:32 AM.. |
|
||||
|
Well, I got it myself. I missed the double quotes when using the variable (not a declaration time of the variable)!
Code:
#!/bin/ksh
typeset pattern="[a-zA-Z ]{30}:"
echo "Command to be executed: grep -E $pattern myFile"
grep -E "$pattern" myFile
![]() |
|
||||
|
Hi,
I'm back with a similar issue ![]() Basically I'm grep'ing a file for a pattern. The pattern contains " (double quotes) and a space. So I escaped the quotes. But how do I use this variable in the grep call? Code:
typeset searchString="path=\"asdf\" mode=\"jkl\"" typeset found=`grep "$searchString" $cs_rte_configtransform` #(a) typeset found=`grep '$searchString' $cs_rte_configtransform` #(b) Code:
typeset searchString="path=\\\"asdf\\\" mode=\\\"jkl\\\"" Has anyone an idea/hint for me? Thanks, regards, Thinkpositiv |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|