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 > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-04-2008
racbern racbern is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 26
help with Sed Command

Hi All,

I am trying to create a script using sed to search for a . and _ on a variable, and if it finds match, remove any value after a . or _.

For Example :

H.3 --> New Value should be H
R2K_CL --> New value should be R2K

Here's the command that I used:
# echo $var | sed 's/[._].*$//'

But my problem is when the variable has several . or _
It should only remove the value after the last . or _.

For Example:
C4.1.2 --> New Value should be C4.1

How will I update my sed command to just remove the value after the last occurrence of a . or _?

Thanks,
racbern