The UNIX and Linux Forums  

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



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to handle backslash in grep string rajbal UNIX for Advanced & Expert Users 6 06-18-2007 09:22 PM
How ro handle backslash character in grep? rajbal Shell Programming and Scripting 1 06-18-2007 09:19 PM
ignoring backslash while executing command agalkin Shell Programming and Scripting 6 11-16-2005 06:04 PM
backslash issues Bab00shka UNIX for Dummies Questions & Answers 5 07-09-2004 09:53 AM
Adding a backslash to users' input netguy Shell Programming and Scripting 13 04-30-2004 06:06 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-19-2008
potro's Avatar
potro potro is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 61
Sed and awk backslash characters

Hi,

I have a variable read from user input:
PROFILESROOTDIR="\\194.185.82.188\CMSRepository\EncodingProfiles"


awk -F"=" -v gr=$PROFILESROOTDIR '/ProfilesRootDirectoryFromXOEMachine/{$2=gr;}1' OFS="=" $CFGFILE > "${CFGFILE}_new"

For this awk to work properly I need to replace in the variable each \ character with \\\ using sed but I just can't manage to do that.

Thanks,
Bianca
  #2 (permalink)  
Old 05-19-2008
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172
Code:
echo '\\194.185.82.188\CMSRepository\EncodingProfiles' | sed 's%\\%\\\\\\%g'
  #3 (permalink)  
Old 05-19-2008
potro's Avatar
potro potro is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 61
Quote:
Originally Posted by agn View Post
Code:
echo '\\194.185.82.188\CMSRepository\EncodingProfiles' | sed 's%\\%\\\\\\%g'
If I use this in the script
PROFILESROOTDIR1=`echo $PROFILESROOTDIR |sed 's%\\%\\\\\\%g'`

I get
sed: -e expression #1, char 9: unterminated `s' command


Bianca
  #4 (permalink)  
Old 05-19-2008
divh18 divh18 is offline
Registered User
  
 

Join Date: May 2008
Posts: 7
I think it should be / instead of % in the code..

Quote:
Originally Posted by potro View Post
If I use this in the script
PROFILESROOTDIR1=`echo $PROFILESROOTDIR |sed 's%\\%\\\\\\%g'`

I get
sed: -e expression #1, char 9: unterminated `s' command


Bianca
  #5 (permalink)  
Old 05-19-2008
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172
Try this:

Code:
PROFILESROOTDIR=$(echo $PROFILESROOTDIR | sed 's%\\%\\\\\\%g')
  #6 (permalink)  
Old 05-19-2008
potro's Avatar
potro potro is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 61
Quote:
Originally Posted by agn View Post
Try this:

Code:
PROFILESROOTDIR=$(echo $PROFILESROOTDIR | sed 's%\\%\\\\\\%g')
There is a problem with function used to read user's input
readDefault()
{
ARGS=""
N=1
LOCALBUF=""
until [ $N -eq $# ]
do
eval ARG=\${$N}
ARGS=" $ARGS $ARG"
N=`expr $N + 1`
done
read $ARGS LOCALBUF
if [ -n "$LOCALBUF" ]
then
VARNAME=${!#}
export $VARNAME=$LOCALBUF
else
echo "Using current value."
fi
}

echo "Please type directory where the profiles are placed: (current value: $PROFILESROOTDIR)"
readDefault -e PROFILESROOTDIR

In this function the \ character is ignored from variable given by user and removed from it.

DO you have any ideea how to ignore the \ characters in this function?

Thanks,
Bianca
  #7 (permalink)  
Old 05-19-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The read command parses backslashes. If you have a reasonably modern shell, it might have read -r for "raw" input without any special treatment of backslashes.
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 On




All times are GMT -4. The time now is 06:47 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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0