Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
ok....i know i am a TOTAL novice...
this is what i need to know how to do..
(it will get me in good with the boss...
no one knows unix here)simple script...
#1...lookup a string in a text file
on that line, there are lists of numbers,
(high temperature, low temperature, current temperature)
#2...find the current temperature from that line
#3 replace a string in another file with that
looked-up temperature.
#4 save the new file!the hints i have are grep and sed
i know i have no clue...
but if ANYONE can help me with this one...
you will have a friend for life...please EMAIL ME seanarcher@hotmail.com
as i cannot surf the web from work..you will make MANY OF US very happy!!!
thanks so much.
sean

(If you can post, you can read; I'm not sending personal email. :-) Besides, responses can be added to or learned from by others...and, we all will know if someone has already responded to you. Isn't that why we have Message Boards?)
Let me rehash your problem as I understand it...
tempfile1 contains high, low and current temps like:
100.0 50.0 90.0tempfile2 contains h, l, c temps like:
110.0 60.0 80.0Replace the 3rd column in tempfile2 with the 3rd column from tempfile1.
I wrote a script called updatetemp:
#!/bin/sh
currtemp=`awk '{print $3}' tempfile1`
printf "%s %s %s\n" `awk '{print $1, $2}' \
tempfile2` $currtemp > tempfile2tempfile2 will now look like:
110.0 60.0 90.0Notes:
I used the line continuation symbol \ in the above script, but this can be removed in your script if you put the last two lines on the same line. I did this so it is readable on this board.After creating the script, be sure to "chmod 777 updatetemp" so you can execute it.
This script may change the format of tempfile2 since it delimits the columns with spaces. It's a bit messy, I know. :-)
I didn't want to use sed to replace the value in tempfile2 since other temps could match and be inadvertently replaced.
Martin

I think we are close martin....
but in reality, i need to replace as string,
in a totally different file, with the temperature i "grab" from the text file...the file i am using is located on the web
(yes, we have their permission!)http://www.LCRA.org/water/temperature.html
now the idea, is to save that file to my machine (as a text file)
and then lookup certain temperatures
(say the current value, from the first 4 cities)and then grab those numbers, and have those values replace "vvv", "www", "xxx" and "yyy"
in my other file.see, that way, we can display those temperature values
the reason we have "vvv" "xxx" in the dummy script, is so that when we replace, there is no ambiguity and we don't replace some more
common string.so again....
(and you are AMAZING to help me by the way)
we have the dummy file ready to go
we need to look at the text file...
choose the correct 4 lines
have the script "lookup" those 4 values,
and then plop those values into the dummy
by replacing the xxx,yyy etc!i hope this makes sense.
and someday, i will buy you lunch!sean

Hi
I need help to write a unix shell script for
changing currency to canadian or us and other countries. Can anyone please help.
I am new to unix and need helpThanks
Mya

Mya, I would suggest that you start a new post on this forum, rather than reply to this older post, so that you will get more visibility. And when you do, be as specific as you can regarding what you have now (such as a unix file with 5 columns of data ...) and what you want to end up with.
James

![]() |
![]() |
![]() |

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