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 07-16-2008
FunibonE FunibonE is offline
Registered User
  
 

Join Date: Jul 2008
Location: Silicon Forest
Posts: 16
partial word replacement using sed

Example contents of a file:

001FILE
002FILE
003FILE
099FILE
111FILE

Is it possible to search for [000-111]FILE and still keep the number part of the result in tact? The number portion is a changing variable but the FILE part stays the same. I want to search for all [000-111]FILE and space them out to "001 FILE" "002 FILE" etc.

If I use sed 's/[000-111]FILE/&/g' It will basically replace with the same variable as found in search.

I know how to search for the variable but don't know how to keep a portion of the result. The cut function would be nice but I can't seem to be able to call it in through sed.

Searching for FILE and adding a space is not an option as some of the other contents have the same names and cannot be effected.

Any ideas?