AWK processing of a three-column file


 
Thread Tools Search this Thread
Top Forums Programming AWK processing of a three-column file
# 1  
Old 01-20-2012
AWK processing of a three-column file

I have a 3-column data file, for which I wish to print certain parts of $3

Code:
PHI         PSI       A(x)
-177.5 -177.5 1.0625
-177.5 -172.5 0.55
-177.5  -167.5 0.0478125
-177.5 -162.5 0
-177.5 -157.5 0.284375
-177.5  -152.5 0.187188
-177.5 -147.5 0.236875
-177.5 -142.5 0.383438
-177.5  -137.5 0.720938
-177.5 -132.5 1.11906
-177.5 -127.5 1.47406
-177.5  -122.5 1.61094
-177.5 -117.5 1.81344
-177.5 -112.5 1.96156
-177.5  -107.5 2.11969
-177.5 -102.5 2.23438
-177.5 -97.5 2.38438
-177.5  -92.5 2.53969
-177.5 -87.5 2.46938
-177.5 -82.5 2.64406
-177.5  -77.5 2.84781
-177.5 -72.5 2.79375
-177.5 -67.5 3.25781
-177.5  -62.5 3.48031
-177.5 -57.5 3.975
-177.5 -52.5 4.30406
-177.5  -47.5 4.79688
-177.5 -42.5 5.21844
-177.5 -37.5 5.88375
-177.5  -32.5 6.56906
-177.5 -27.5 7.15531
-177.5 -22.5 7.75125
-177.5  -17.5 8.38563
-177.5 -12.5 8.92563
-177.5 -7.5 9.37313
-177.5  -2.5 9.9325
-177.5 2.5 10.6044
-177.5 7.5 10.6159

...
until +180


I want to access a certain range of the data, e.g. print $3 when the following conditions are met:
PHI 50 to 100 and PSI -70 to -90

which would give the following data:
Code:
52.5 -87.5  4.61531
52.5 -82.5 4.59969
52.5 -77.5 4.45344
52.5 -72.5 4.245

57.5  -87.5 4.24344
57.5 -82.5 4.0775
57.5 -77.5 3.90438
57.5 -72.5  3.86375

62.5 -87.5 3.84125
62.5 -82.5 3.76875
62.5 -77.5  3.63406
62.5 -72.5 3.39844

67.5 -87.5 3.73563
67.5 -82.5  3.65938
67.5 -77.5 3.60906
67.5 -72.5 3.31

72.5 -87.5  3.73688
72.5 -82.5 3.61813
72.5 -77.5 3.45938
72.5 -72.5  3.27969

77.5 -87.5 4.01219
77.5 -82.5 3.61063
77.5 -77.5  3.555
77.5 -72.5 3.43531

82.5 -87.5 4.32906
82.5 -82.5  4.00188
82.5 -77.5 3.83781
82.5 -72.5 4.08438

87.5 -87.5  4.89344
87.5 -82.5 4.60594
87.5 -77.5 4.6525
87.5 -72.5 4.54781

92.5  -87.5 5.455
92.5 -82.5 5.32375
92.5 -77.5 5.18188
92.5 -72.5  5.35219

97.5 -87.5 6.19656
97.5 -82.5 6.05938
97.5 -77.5  6.01063
97.5 -72.5 6.30094

Then I want to post-process this data
Any help here?

Last edited by chrisjorg; 01-20-2012 at 03:46 PM..
# 2  
Old 01-20-2012
Try:
Code:
awk '$1>=50&&$1<=100&&$2>=-90&&$2<=-70' file

# 3  
Old 01-21-2012
Ok, thanks, now my output data is of the form:

Code:
4.61531
4.59969
4.45344
4.245
4.24344
4.0775
3.90438
3.86375
3.84125
3.76875
3.63406
3.39844
3.73563
3.65938
3.60906
3.31
3.73688
3.61813
3.45938
....etc...

and I have called the two data files I have c7eq.dat (dimension 25:1) and c7ax.dat (dimension 41:1)



In my Fortran program I wish to process this data:

Code:
Program average_2
      implicit none
      double precision, dimension (25:1) :: H
      double precision, dimension (41:1) :: G

      open (unit=2, file="c7eq.dat", form="unformatted")
      read (2) G
      open (unit=3, file="c7ax.dat", form="unformatted")
      read (3) H

However I get the error:
forrtl: severe (24): end-of-file during read, unit 2, file /home/guest/c7eq.dat

Anyone can help me here?

---------- Post updated at 10:31 AM ---------- Previous update was at 09:06 AM ----------

The error further says

Image PC Routine Line Source
Exercise8.exe 08088DE2 Unknown Unknown Unknown
Exercise8.exe 08087D59 Unknown Unknown Unknown
Exercise8.exe 08087CD5 Unknown Unknown Unknown
Exercise8.exe 0805FB82 Unknown Unknown Unknown
Exercise8.exe 0805F8B2 Unknown Unknown Unknown
Exercise8.exe 0805568F Unknown Unknown Unknown
Exercise8.exe 08049DCC Unknown Unknown Unknown
Exercise8.exe 08049BE9 Unknown Unknown Unknown
libc.so.6 F7C1C390 Unknown Unknown Unknown
Exercise8.exe 08049B11 Unknown Unknown Unknown
# 4  
Old 01-21-2012
Hi.

Are you sure that you have unformatted data? What do you think that means? ... cheers, drl
This User Gave Thanks to drl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Processing a formatted file with awk

Hi - I want to interrogate information about my poker hands, sessions are all recorded in a text file in a particular format. Each hand starts with the string <PokerStars> followed by a unique hand reference and other data like date/time. There is then all the information about each hand. My first... (5 Replies)
Discussion started by: rbeech23
5 Replies

2. Shell Programming and Scripting

Help with file processing using awk

hello All, I'm new to AWK programming and learned myself few things to process a file and deal with duplicate lines, but I got into a scenario which makes me clueless to handle. Here is the scenario.. Input file: user role ----- ---- AAA add AAA delete BBB delete CCC delete DDD ... (10 Replies)
Discussion started by: julearn
10 Replies

3. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

4. Shell Programming and Scripting

Awk: Need help replacing a specific column in a file by part of a column in another file

Hi, I have two input files as File1 : ABC:client1:project1 XYZ:client2-aa:project2 DEF:client4:proj File2 : client1:W-170:xx client2-aa:WT-04:yy client4:L-005A:zz Also, array of valid values can be hardcoded like Output : ABC:W:project1 XYZ:WT:project2 (1 Reply)
Discussion started by: aa2601
1 Replies

5. Shell Programming and Scripting

Help with File processing - Extracting the column

I have a line from table space report: 5 135_TT ms Normal 1774336.0 1774208.0 761152.0 1013056.0 57.1% Now I have to get 1013056.0 as o/p. For this I tried cut -f32 -d" " previously it worked now it is showing empty space. Suggest me the best code for this which... (1 Reply)
Discussion started by: karumudi7
1 Replies

6. Shell Programming and Scripting

Help with File Processing (AWK)

Input File: 1234, 2345,abc 1,24141,gw 222,rff,sds 2232145,sdsd,121 Output file to be generated: 000001234,2345,abc 000000001,24141,gw 000000222,rff,sds 002232145,sdsd,121 i.e; the first column is padded to get 9 digits. I tried with following: (3 Replies)
Discussion started by: karumudi7
3 Replies

7. Shell Programming and Scripting

Help with File Processing (AWK)

Input File: 1234, 2345,abc 1,24141,gw 222,rff,sds 2232145,sdsd,121 Output file to be generated: 000001234,2345,abc 000000001,24141,gw 000000222,rff,sds 002232145,sdsd,121 i.e; the first column is padded to get 9 digits. I tried with following: (1 Reply)
Discussion started by: karumudi7
1 Replies

8. Shell Programming and Scripting

awk help in processing file.

I am trying to process file which has following data #23456789012345 ACNASPSA13N0N0 ACNAPCPA05N0N0 ACNAFATS11N0N0 I want to take out each line from the file and what to put in the file by name which if part of the line starting from offset 10 to 15. It means I want to create three file... (3 Replies)
Discussion started by: ekb
3 Replies

9. Shell Programming and Scripting

AWK processing -numbers to another column

Hi Guys, I'm trying to clean up my home logger file and can't seem to work this out. Here is my data: 10-19-2009 08:39 00.2 00.0 00.7 01.1 49.1 0.0 11.9 270.1 -49.1 220.9 10-19-2009 08:40 00.2 00.0 00.7 00.7 49.1 0.0 171.9 171.9 49.1 220.9 10-19-2009 08:41 00.1 00.0 00.7 00.8 24.5 0.0... (2 Replies)
Discussion started by: BeJay
2 Replies

10. Shell Programming and Scripting

processing a file with sed and awk

Hello, I have what is probably a simple task in text manipulation, but I just can't wrap my brain around it. I have a text file that looks something like the following. Note that some have middle initials in the first field and some don't. john.r.smith:john.smith@yahoo.com... (4 Replies)
Discussion started by: manouche
4 Replies
Login or Register to Ask a Question