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:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old March 4th, 2005, 04:21 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.

1125 0.944 200.00

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

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 5th, 2005, 02:19 PM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,296 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 5 m 9 sec
Reputation Power: 101
Send a message via ICQ to christo Send a message via Yahoo to christo
if your file is called values.txt, then you just need to do this at your command line:


perl -pi -e 's/^/House /' values.txt



hope that helps


christo

Reply With Quote
  #3  
Old March 7th, 2005, 06:45 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by christo
if your file is called values.txt, then you just need to do this at your command line:


perl -pi -e 's/^/House /' values.txt



hope that helps


christo



If you have no perl, write

sed 's/^/House /' values.txt

Regards

Reply With Quote
  #4  
Old March 7th, 2005, 08:17 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,078 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 14 h 28 m 26 sec
Reputation Power: 9
christo + zlutovsky

your approach will change
Quote:
1125 0.944 200.00
1125 XXXX 200.00

to
Quote:
House 1125 0.944 200.00
House 1125 XXXX 200.00

is that expected ? i read this:
Quote:
The only constant value in the line is the 0.944 value.

insert 'home' to all lines containing '0.944' in the 2.nd field.
this thread is duplicated, i wrote a sed-cmd in other one
__________________
working on Solaris[5-9], preferred languages french and C.

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 2 hosted by Hostway