How can I get the required result?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I get the required result?
# 1  
Old 05-15-2013
Question How can I get the required result?

Hi, guys. I have a question. Please help me~
I got an text, recording the weather reports. It is the Attachment "Weather Forcast_original.txt"
Weather Forcast_original.txt
I want to get the required result like the attachment "Weather Forcast_formatted.txt"
Weather Forcast_formatted.txt
I thought about the loop, the conditions, but I'm surely confused now. I have no idea. What am I supposed to do?
Could you guys provide the simple workflow and the code together?
Thank you very much!
# 2  
Old 05-15-2013
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.


Thank you.

The UNIX and Linux Forums
# 3  
Old 05-15-2013
Hi, guys. I've complete half of the question I asked this morning.
I got a middle course, which is the attachment "weather_formatting.txt"
And my code are listed below:
Code:
#!/bin/sh
# scriptname : weather_format
# purpose : to format the original weather forcast
i=1
j=1
while [ $i -lt `wc -l $1 | gawk 'BEGIN{FS=" "}{printf $1}'` ]
do
	if echo `sed -n "$i""p" $1` | grep "New York"
	then
		j=$i
		sed -n "$j""p" $1 >> ./weather_formatting.txt
		j=`expr $j + 1`
		until echo `sed -n "$j""p" $1` | grep -E "New York|Ottawa"
		do
			sed -n "$j""p" $1 >>./weather_formatting.txt
			j=`expr $j + 1`
		done
		i=$j
	else
		i=`expr $i + 1`
	fi
done

However, I really hope some guys can help me to complete it. And I felt I was a little confused in my mind. Maybe the code can be terser and more efficient.
Thanks!
# 4  
Old 05-15-2013
Here is an awk code that might help:
Code:
awk '
        BEGIN {
                print "##############    Weather Forcasts for Primary Cities in U.S.     ##############"
                print "--------------------------------------------------------------------------------"
        }

        NR == 1 {
                H = "Location        Temperature(F)  Precipiation(%)         Humidity(%)     Wind(mph)"
        }

        NR > 1 {
                T = $( NF - 4 )
                A[T] = $0
                P = $0
                sub ( /[0-9].*/, X, P )
                V[P","T] = $0
        }

        END {
                for ( k in A )
                {
                        printf "\nTime : %s\n", k
                        print  H
                        for ( p in V )
                        {
                                if ( p ~ k )
                                {
                                        sub ( k, X, V[p] )
                                        print V[p]
                                }
                        }
                }
        }
' file

Also note that this code doesn't have a sorting mechanism on date field which I guess you have to work on.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

2. UNIX for Dummies Questions & Answers

Help me in getting the desired result

Hi All, I have input file which is pipe delimited A | 1 B | 2 c | 3I need output of displaying total number of lines in a file as last column. A | 1 | 3-----total number of linesin file. B | 2 | 3 c | 3 | 3 (9 Replies)
Discussion started by: pravinashwin
9 Replies

3. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

4. UNIX for Dummies Questions & Answers

what is the result of this?

ls -A $variable (2 Replies)
Discussion started by: prathimahsc
2 Replies

5. UNIX for Dummies Questions & Answers

what is the result of this?

if ] (1 Reply)
Discussion started by: prathimahsc
1 Replies

6. Shell Programming and Scripting

What syntax is required so that result will start from a new line..

What syntax is required to start the result in a new line (7 Replies)
Discussion started by: sapan123
7 Replies

7. UNIX for Dummies Questions & Answers

display the result of wc -l with words before and after the result

hello showrev -p | wc -l returns: 381 What to do in case I want to have this output: number of lines returned by showrev -p is: 381 thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

8. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

9. Shell Programming and Scripting

sftp result

Hi, I have a sftp account to another server, from which I need to find out all the files match "*.abc.*.xml" pattern in a certain directory. I have a batchfile as follows cd /tmp ls -l *.abc.*.xml quit then I run output=`/usr/local/bin/sftp -B $batchfile $USER@$HOST` the result looks... (2 Replies)
Discussion started by: mpang_
2 Replies

10. Shell Programming and Scripting

sFTP result

Hi all, batchfile ====== lcd /home/data/ cd /tmp/source/ get "*.temp.ack" quit Result from sftp ============ 1111.temp.ack| 0B | 0B/s | TOC: 00:00:01 | 100%^M ^M2222.temp.ack | 0B | 0B/s | TOC: 00:00:01 | 100%^M ^M3333.temp.ack | 0B | 0B/s | TOC: 00:00:01 | 100%^M ^M As I don't know... (4 Replies)
Discussion started by: mpang_
4 Replies
Login or Register to Ask a Question