The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 10 12-02-2008 07:58 AM
parsing a string in a shell script asutoshch Shell Programming and Scripting 19 05-26-2008 09:18 PM
bash script to check the first character in string ole111 Shell Programming and Scripting 2 03-19-2008 12:34 AM
shell script string extension vbm Shell Programming and Scripting 4 11-10-2006 01:58 AM
Special Character Check in Shell script mradul_kaushik Shell Programming and Scripting 1 03-24-2006 05:54 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-26-2001
ThuongTranVN ThuongTranVN is offline
Registered User
  
 

Join Date: Jan 2001
Location: Rochester NY,USA
Posts: 3
Post Shell Script: Cut '\' character in string

I have a string "\/scratch\/databases\". I want
to have a new string "\/scratch\/databases" by cutting last '\' character using shell script. I can't do this
Please help me.
Thanks in advance
ThuongTranVN




[Edited by ThuongTranVN on 01-26-2001 at 01:35 PM]
  #2 (permalink)  
Old 01-27-2001
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,667
\\

You must use a \ in front of the \ to make it a \\ in your search and replace functions because of the special nature (meta) of the \ char. Example in vi editor:

Code:
:%s/\\$//
The fragment above says "search for the \ at the end of a line and replace with nothing"

Note. that I've not tested the fragment above and it might need some more tweaking to work.

[Edited by Neo on 01-29-2001 at 05:03 PM]
  #3 (permalink)  
Old 01-29-2001
ThuongTranVN ThuongTranVN is offline
Registered User
  
 

Join Date: Jan 2001
Location: Rochester NY,USA
Posts: 3
Re: \\

Hello,
Thank you so much for your reply.
I tried
Code:
:%s/\\$// don't replcae '\' character at the end of line
:%s/\\// replace only first '\' character of line
:%s/\\//g replace all '\' characters of line.

I need help.
Thanks in advance
  #4 (permalink)  
Old 01-29-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
If you want to do it in vi, I would use this:

:g/\\$/s///


Your original post said you are trying to write a shell script. In which case, you could do:

FOO='\/scratch\/databases\'
echo $FOO | sed 's/\\$//'
  #5 (permalink)  
Old 01-30-2001
ThuongTranVN ThuongTranVN is offline
Registered User
  
 

Join Date: Jan 2001
Location: Rochester NY,USA
Posts: 3
Thank you so much for your help.
I've got it as follows:
FOO="\/scratch\/databases"
echo $FOO | sed 's/\\$//' > tmp.log
DAEHOME=`cat tmp.log`
I can not use
DAEHOME=`echo $FOO | sed 's/\\$//'`
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:29 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