The UNIX and Linux Forums  


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
Need a regular expression tony3101 Shell Programming and Scripting 4 06-05-2008 04:13 AM
regular expression and awk nickg UNIX for Dummies Questions & Answers 2 08-16-2007 06:23 PM
regular expression...help!! andy2000 UNIX for Dummies Questions & Answers 6 07-18-2007 06:10 PM
help in regular expression Rakesh Ranjan High Level Programming 5 10-25-2006 02:00 PM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 11:59 AM

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 12-04-2003
edog edog is offline
Registered User
  
 

Join Date: Sep 2001
Location: Green Bay, WI
Posts: 66
Regular Expression

OK, this ones been bugging me....

9DH21AQAE~56081~109~12/18/2003~ ~B ~ ~


I want to remove all but 1 of the trailing spaces after the last ~, there may be 2 or more trailing spaces

tried

s/\~ +/\~ /g but no go

thanks
  #2 (permalink)  
Old 12-04-2003
tikual tikual is offline
Registered User
  
 

Join Date: Nov 2003
Location: HK
Posts: 53
I think that you are trying to edit the file in vi, right? Actually I don't know what result you want.

if you want the following result.
9DH21AQAE~
then
:s/\~[^~]*.*$/\~/

9DH21AQAE~56081~
then
:s/\(^[^~]*\~[^~]*\~\).*$/\1/

9DH21AQAE~56081~109~
skipped, refer to above reference

9DH21AQAE~56081~109~12/18/2003~
skipped, refer to above reference

if you want to remove the last ~
9DH21AQAE~56081~109~12/18/2003~ ~B ~
then
:s/\(^.*\)\~$/\1/
  #3 (permalink)  
Old 12-04-2003
edog edog is offline
Registered User
  
 

Join Date: Sep 2001
Location: Green Bay, WI
Posts: 66
Right now I am testing in vi but eventually the replace will be put into a script.

what I want is to remove all but 1 trailing space:

9DH21AQAE~56081~109~12/18/2003~ ~B ~ ~ <space> <space> ..............

to

9DH21AQAE~56081~109~12/18/2003~ ~B ~ ~<space>

there will be 1 or more trailing spaces but I only ever want 1 space after the last ~
  #4 (permalink)  
Old 12-04-2003
tikual tikual is offline
Registered User
  
 

Join Date: Nov 2003
Location: HK
Posts: 53
ok, got your meaning now.

try it
s/\(^.*\~\) *$/\1/
  #5 (permalink)  
Old 12-04-2003
tikual tikual is offline
Registered User
  
 

Join Date: Nov 2003
Location: HK
Posts: 53
sorry, a typo found

s/\(^.*\~\) *$/\1 / <--- one space behind \1
  #6 (permalink)  
Old 12-04-2003
edog edog is offline
Registered User
  
 

Join Date: Sep 2001
Location: Green Bay, WI
Posts: 66
Thanks tikual,

works great!
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 02:16 AM.


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