Computing.Net > Forums > Unix > UNIX HELP

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 HELP

Reply to Message Icon

Name: seanarcher
Date: November 6, 2001 at 17:56:36 Pacific
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Martin Blazevich
Date: November 6, 2001 at 21:12:19 Pacific
Reply:

(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.0

tempfile2 contains h, l, c temps like:
110.0 60.0 80.0

Replace 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 > tempfile2

tempfile2 will now look like:
110.0 60.0 90.0

Notes:
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


0

Response Number 2
Name: seanarcher
Date: November 7, 2001 at 09:38:10 Pacific
Reply:

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



0

Response Number 3
Name: Mya
Date: November 12, 2001 at 14:43:35 Pacific
Reply:

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 help

Thanks
Mya


0

Response Number 4
Name: James Boothe
Date: November 13, 2001 at 06:12:37 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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 HELP

NEED TO PRINT HTML IN UNIX! HELP! www.computing.net/answers/unix/need-to-print-html-in-unix-help/2834.html

Sco Unix Help www.computing.net/answers/unix/sco-unix-help/3744.html

unix help!! www.computing.net/answers/unix/unix-help/5339.html