output in another file in one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting output in another file in one line
# 1  
Old 02-25-2010
output in another file in one line

Hello,

I know this is maybe a stupid question, but I have an output like this:
Code:
# gensky 1 1 1:00YST +s -a37.24 -o126.58
# Local solar time: 1.80
# Solar altitude and azimuth: -55.1 -47.0
# Ground ambient level: 0.0

void brightfunc skyfunc
2 skybr skybright.cal
0
7 1 0.00e+00 0.00e+00 3.34e-01 0.418328 -0.390099 -0.820259

There are 1000 of files like that with different results. And I want to pipe it into another file to have a table I can work further on. But being dependend on the different lines, the output looks like that:
Code:
1.80
-55.1 -47.0
0.0
1 0.00e+00 0.00e+00 3.34e-01 0.418328 -0.390099 -0.820259

But the result should be like this with a new line for each file:
Code:
1.80 -55.1 -47.0 0.0 1 0.00e+00 0.00e+00 3.34e-01 0.418328 -0.390099 -0.820259

That's how the code looks right now:
Code:
cat Seoulhour.wea |awk '{
    
    b=sprintf("gensky %1$s %2$s %3$s:00YST +s -a37.24 -o126.58 >> az_%1$s_%2$s_%3$s.sky\n", $1, $2, $3)
    print "str", b
    system(b)
    }'

for i in az_*.sky
do    
    cat $i |awk '{
        if (NR==2) {
            print $5, " " >> "erg_azimuth.dat"
            #Local solar time
            }
        if (NR==3) {    
            print $6, " " $7, " "  >> "erg_azimuth.dat"
            #Solar altitude and azimuth
            }
        if (NR==4) {
            print $5  >> "erg_azimuth.dat"
            #Ground ambient level
            }
        if (NR==9) {
            print $2, " "$3, " "$4, " "$5, " "$6, " "$7, " "$8   >> "erg_azimuth.dat"
            #Ground ambient level
            }
        }'
done

I also tried something like this instead, but it doesn't work:
Code:
b=sprintf("gensky %1$s %2$s %3$s:00YST +s -a37.24 -o126.58 |grep alti |awk \"{print $6,$7}\">> az_%1$s_%2$s_%3$s.sky\n", $1, $2, $3)
print "str", b
system(b)

Does soemone has an idea?
Thanks a lot for any answer,
Sandra
# 2  
Old 02-25-2010
Hi, ergy1983:

Using printf should do the trick:
Code:
    cat $i |awk '{
        if (NR==2) {
            printf("%s ", $5) >> "erg_azimuth.dat"
            #Local solar time
            }
        if (NR==3) {
            printf("%s %s ", $6, $7) >> "erg_azimuth.dat"
            #Solar altitude and azimuth
            }
        if (NR==4) {
            printf("%s ", $5) >> "erg_azimuth.dat"
            #Ground ambient level
            }
        if (NR==9) {
            printf("%s %s %s %s %s %s %s\n", $2, $3, $4, $5, $6, $7, $8)  >> "erg_azimuth.dat"
            #Ground ambient level
            }
        }'

Cheers,
Alister
# 3  
Old 02-25-2010
hey alister,

thanks a lot. This works perfectly. Yeah and it is so simple, that I should have found it by myself, but sometimes...

So thanks again for the quick answer,
Sandra
# 4  
Old 02-25-2010
You're welcome.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

3. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

4. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

5. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

6. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

7. Shell Programming and Scripting

egrep output each file in new line

I have the following script that searches in several files and shows the search results and the matches filename on the screen. find . -exec egrep -wH "word1|word2" {} \; the output from the search display as: file1 word1 word2 I need to show each file search output result on new... (5 Replies)
Discussion started by: konddor
5 Replies

8. Shell Programming and Scripting

Insert output into file at line number

I need to insert the output of a script into a specific line number of a txt file. I've read the Sed man page and searched the forums and it's not immediately clear how I would go about doing this. (4 Replies)
Discussion started by: pluto7777
4 Replies

9. Shell Programming and Scripting

print out a line from a output file

I am trying to have a script ping all the clients then output it to a file so I know which clients are off then have the next script pull the ones that are online and reboot them. This is what I am running with right now. If there is something KISS then by all means please let me know. ... (3 Replies)
Discussion started by: deaconf19
3 Replies

10. Shell Programming and Scripting

Get specified line as output from a file

hi all, One simple question. How to print a perticular line from a file. For example if a file "test" has some list of commands as below ls chfn cut grep ... ... ... now i have to print 3 rd line of it i.e expected output is to be"cut".. Can you please help me ... ... (5 Replies)
Discussion started by: Chanakya.m
5 Replies
Login or Register to Ask a Question