UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old March 4th, 2005, 04:22 PM
caspercoco caspercoco is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 7 caspercoco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 53 m 28 sec
Reputation Power: 0
Exclamation find and replace

Hello,

I would like some advice re the following.

Suppose I have a file that contains many rows of data. The following line appears approx 1000 times in the file.

"some other data" 1125 0.944 200.00

I would like the line to read (for all 1000 lines)

"some other data" House 1125 0.944 200.00

The only constant value in the line is the 0.944 value.

Thanks in advance.

Reply With Quote
  #2  
Old March 4th, 2005, 11:37 PM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
Quote:
Originally Posted by caspercoco
Hello,
"some other data" 1125 0.944 200.00

I would like the line to read (for all 1000 lines)

"some other data" House 1125 0.944 200.00


assumed your exemple, on *nix try
sed 's/\(.*\) \([0-9]*[0-9]\) \(0\.944\) \(.*\)/\1 House \2 \3 \4/' inputfile >outputfile

NOTA: spaces are relevant
\1 is "some other data"
\2 are the digits after "some other data" and before 0.944
\3 is 0.944
\4 is all after 0.944

very similar syntax using perl.
__________________
working on Solaris[5-9], preferred languages french and C.

Last edited by guggach : March 5th, 2005 at 08:11 AM. Reason: typos

Reply With Quote
  #3  
Old March 5th, 2005, 01:58 AM
caspercoco caspercoco is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 7 caspercoco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 53 m 28 sec
Reputation Power: 0
Quote:
Originally Posted by guggach
assumed your exemple, on *nix try
sed 's/\(.*\) \([0-9]*[0-9]) \(0\.944) \(.*\)/\1 House \2 \3 \4/' inputfile >outputfile

NOTA: spaces are relevant
\1 is "some other data"
\2 are the digits after "some other data" and before 0.944
\3 is 0.944
\4 is all after 0.944

very similar syntax using perl.


great

Last edited by caspercoco : March 6th, 2005 at 03:07 PM. Reason: ta

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > find and replace


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway