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



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
Partial Request are coming... please help pa.chidhambaram IP Networking 0 02-05-2008 11:19 AM
Can a shell script pull the first word (or nth word) off each line of a text file? tricky Shell Programming and Scripting 5 08-17-2006 06:29 AM
vsftpd hiding partial uploads jhod22 Linux 3 07-08-2006 04:49 PM
Grep all files matching partial filename mharley Shell Programming and Scripting 3 06-08-2005 02:17 PM
Interested in partial command output. videsh77 UNIX for Dummies Questions & Answers 1 12-15-2004 10:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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?
  #2 (permalink)  
Old 07-16-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,861
Code:
sed -e 's/^[0-1][0-9][0-9]/& /'  file
  #3 (permalink)  
Old 07-16-2008
FunibonE FunibonE is offline
Registered User
  
 

Join Date: Jul 2008
Location: Silicon Forest
Posts: 16
Quote:
Originally Posted by fpmurphy View Post
Code:
sed -e 's/^[0-1][0-9][0-9]/& /'  file
Thank you but this file has other numbered variables too so I cannot search for numbers alone or characters alone. I must be able to search for 001FILE as a whole and then split the output into 001 FILE.

On another note, it doesn't have to be sed. I'm working on Sun Solaris 10 so which ever utility available by default will work too.

Any other ideas?
  #4 (permalink)  
Old 07-16-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Not sure I fully understand the requirements, but try this variation:

Code:
sed -e '/^[0-1][0-9][0-9]FILE/s/^[0-1][0-9][0-9]/& /'  file
If that isn't what you want, give us some more sample input data (including the lines you don't want to change) and the output you expect from that data.
  #5 (permalink)  
Old 07-17-2008
FunibonE FunibonE is offline
Registered User
  
 

Join Date: Jul 2008
Location: Silicon Forest
Posts: 16
Quote:
Originally Posted by Annihilannic View Post
Not sure I fully understand the requirements, but try this variation:

Code:
sed -e '/^[0-1][0-9][0-9]FILE/s/^[0-1][0-9][0-9]/& /'  file
If that isn't what you want, give us some more sample input data (including the lines you don't want to change) and the output you expect from that data.

Hi. I was trying to keep the question simple but I guess I can't anymore so here is the actual data.

Code:
TRUE 6.8785794488e-05 0.000 0.000 FALSE 6.8785794488e-05 0.000 0.000TRUE 1 FALSE 1 TRUE
TRUE 1.8093516870e-02 0.999 0.030 TRUE 1.8093255236e-02 0.999 0.057TRUE 1 FALSE 1 TRUE
The above is just 2 line of a very large file. The problem is, I need a space between the 0.000 and TRUE so I can import it correctly into excel.

The numbers are not constant and is a changing variable. I need to be able to target just the lines containing [0-1].[0-9][0-9][0-9]TRUE and put a space/tab to separate the number and the TRUE.

Thanks.
  #6 (permalink)  
Old 07-17-2008
sudhamacs sudhamacs is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 98
sed -e '/[0-1][0-9][0-9]TRUE/s/[0-1][0-9][0-9]/& /g' file
  #7 (permalink)  
Old 07-17-2008
FunibonE FunibonE is offline
Registered User
  
 

Join Date: Jul 2008
Location: Silicon Forest
Posts: 16
Thumbs up

Quote:
Originally Posted by sudhamacs View Post
sed -e '/[0-1][0-9][0-9]TRUE/s/[0-1][0-9][0-9]/& /g' file
That worked!
Thank you all very much.
Sponsored Links
Closed Thread

Bookmarks

Tags
solaris

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 08:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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