Computing.Net > Forums > Unix > Unix replacing text

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix replacing text

Reply to Message Icon

Name: sean
Date: November 15, 2005 at 15:05:40 Pacific
OS: inix
CPU/Ram: unix
Comment:

We have a file that looks like this:
Partly Cloudy
33
Windy
Very Very Cold
North 15-25

those values (and spaces in the text)
need to replace text in a different file
that text is: AAA, BBB, CCC, DDD, and EEE

(where AAA is replaced by Partly Cloudy)
and so on...

is there some simple way to do this?!

thanks!
i am a computer novice!




Sponsored Link
Ads by Google

Response Number 1
Name: Ravi kumar
Date: November 15, 2005 at 19:54:26 Pacific
Reply:

Hi

cp file1 file2


0

Response Number 2
Name: nails
Date: November 15, 2005 at 22:51:14 Pacific
Reply:

Hi:

I'm interpreting that you want every line in your file, and placed on one line delimited by a comma and a space. If this is correct, this command should work:

sed 's/$/| /g' mydata.file| xargs |sed 's/|/,/g'

The command above leaves a comma at the end of the line. You don't say whether this is what you want. This command removes the trailing comma:

sed 's/$/| /g' mydata.file| xargs |sed 's/|/,/g' |sed 's/,$//g'


0

Response Number 3
Name: sean
Date: November 17, 2005 at 19:39:19 Pacific
Reply:

actually...there is a GREAT DEAL of text in the target file (HTML, COLORS, OTHER DATA)

We need to be able to create the small file of 5 or six lines on a daily basis...
and then have the script replace the placeholders (AAA etc) with the new data!

the big problem, is when we have
PARTLY CLOUDY as the first line of the
file, we seem to get PARTLY to replace AAA
and CLOUDY to replace BBB
(instead of PARTLY CLOUDY replacing just AAA)

please help us!



0

Response Number 4
Name: nails
Date: November 17, 2005 at 20:54:07 Pacific
Reply:

I guess I'm not understanding your algorithm. How about posting your script and data file?


0

Response Number 5
Name: sean
Date: November 18, 2005 at 19:10:39 Pacific
Reply:

FILE1:

Partly Cloudy
Very Windy
44
Some Fog Late
NE 10-15

FILE2:
!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="sean archer">
<meta name="GENERATOR" content="Mozilla/4.8 [en] (Windows NT 5.0; U) [Netscape]">
<title>ktbc data</title>
<!-- saved from url=(0129)file://C:\Documents%20and%20Settings\ktbcuser\Local%20Settings\Temporary%20Internet%20Files\Content.IE<!-- saved from url=(0129)file://C:\Documents%20and%20Settings\ktbcuser\Local%20Setti</head>
<body>
 
<table BORDER COLS=5 WIDTH="83%" >
<tr>
<td><AAA></td>
<td><BBB></td>
<td><CCC></td>
<td><DDD></td>
<td><EEE></td>


script:
temps=`cat FILE1`
t1=`echo $var|cut -d" " -f1`
t2=`echo $var|cut -d" " -f2`
t3=`echo $var|cut -d" " -f3`
t4=`echo $var|cut -d" " -f4`
t5=`echo $var|cut -d" " -f5`

sed -e 's/AAA/$t1/' -e 's/AAA/$t1/' \
-e 's/AAA/$t1/' -e 's/AAA/$t1/' \
-e 's/AAA/$t1/' \
FILE2 > FILE3


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix replacing text

replace text www.computing.net/answers/unix/replace-text/6952.html

Help needed ! Mail through UNIX ! www.computing.net/answers/unix/help-needed-mail-through-unix-/5187.html

Replace Text www.computing.net/answers/unix/replace-text/6940.html