![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to exclude the GREP command from GREP | yamsin789 | UNIX for Advanced & Expert Users | 2 | 10-04-2007 11:59 PM |
| grep command | Geogia | UNIX for Dummies Questions & Answers | 2 | 06-20-2005 05:12 PM |
| grep command | whatisthis | UNIX for Dummies Questions & Answers | 3 | 09-02-2004 08:01 AM |
| grep command ~ Need help | april04 | Shell Programming and Scripting | 6 | 10-23-2002 12:57 PM |
| grep command | Medhi | Shell Programming and Scripting | 3 | 03-15-2002 04:42 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
help with grep command or other useful command
Hi
I'm new for this forum and actually, I like this forum for the number of experts members that in the forum. First, How do I use grep command to grep the contents of more than one file(with any extension!) to be saved in one single file? For example, I have tried this command grep, but it include the file name too..!! Which i don't want to be included? The command grep I used: grep "[0-9]" *.PUN > allpun.out file1 0001091Y.PUN file2 0001291X.PUN file3 0001302T.PUN ... ... fileN *******.PUN Output file: 0001091Y.PUN:960109 914 4.54 25- 9.21 40-50.34 14.83 2.81 12 335116.5 0.26 6.8 81.7 D1 0001291X.PUN:940129 559 37.02 24-28.93 39-51.79 0.86 1.99 17 151 9.0 0.07 0.2 0.4 B1 0001302T.PUN:940130 1047 38.93 24-53.89 40-44.31 9.52 2.89 20 321 93.9 0.17 1.6 28.7 D1 0001311V.PUN:940131 843 37.78 24-53.54 40-46.08 5.19 2.88 17 322 96.4 0.21 15.9 49.9 D1 But, I don't want the file name to be included in the output file? (the file name start at the beginning of each line and followed by a colon ':', then the contents of each file). How do I do that? Second, how do I grep only, let's say, a range of Latitude and a range of Longitude from the final output file? (Above) Then, I want to convert the Lat and Long columns to decimals numbers? without the '-' sign? For your information, the header of this data files are: DATE ORIGIN LAT N LONG E DEPTH MAG NO GAP DMIN RMS ERH ERZ QM But, this header not included for all files? Looking for any help or point! And I appreciate your help in advance amm |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
1.
Code:
grep -h "[0-9]" *.PUN > allpun.out 2. For second part of your post, did you mean this ? Code:
while read DATE ORIGIN LAT N LONG REST do echo "$LAT" -> "$LONG" done < allpun.out |
|
#3
|
|||
|
|||
|
Hi Vino
Thanks a lot for your help and quick reply. you have solved for me the first problem I have with the file name. Thanks again. It's work..!! Great..!! Regarding the second problem that I have, I think you get confused when I post the header, which is not the normal case. I have post the header to show you an Idea of my data type. That's all. So, what I want exactly is, to convert the Lat and Long column in my output file to the new decimal coordinates system. The output file for allpun.out: 960109 914 4.54 25- 9.21 40-50.34 14.83 2.81 12 335116.5 0.26 6.8 81.7 D1 940129 559 37.02 24-28.93 39-51.79 0.86 1.99 17 151 9.0 0.07 0.2 0.4 B1 940130 1047 38.93 24-53.89 40-44.31 9.52 2.89 20 321 93.9 0.17 1.6 28.7 D1 940131 843 37.78 24-53.54 40-46.08 5.19 2.88 17 322 96.4 0.21 15.9 49.9 D1 So, the Coordinates in this file are in Degree, Minutes and Decimal Minutes. for example, 25- 9.21, are in 25 degree, 9 minute and .21 decimal minutes. What I want is, to convert from this forms to the forms of Degree and Decimal Degree. For example, 25.1535 which is in degree and decimal degree by deviding the 9.21 by 60 and add the result to the degree. For example, 9.21/60=0.1535, adding to the degree, 25+0.1535=25.1535. The final coordinate system is 25.1535 , In degree and decimal degree. That's all. And of course, I wanna do this operations and keeping all other data in its place. This next step, from the output file ABOVE (after converting to new coordinate system), I wanna make a (Grep) selection for my interested range of my Lat and Long to the new output file. (the Minimum Lat and Maximum Lat and Mini. Long and Max. Long). Like a square area!! with Lat and Long in each corner! I'm just explaining the Idea..!! Let's say I wanna make a range of selection from my data file above for a range of Long and Lat. For example, I wanna start from Minimum Latitude 24.30 to Maximum Latitude 25.80. And the same for the Longitude, I wanna start from Min. Long 39.20 to Max Long 40.50. That's all..!! Hope this give more Idea about my case. Thank you in advance, amm |
|
#4
|
|||
|
|||
|
I have got an clumpsy solution,Please try,
Code:
awk '{ split($4,LatD,"-");Deg=LatD[1];Dec=LatD[2];sum=(Deg+Dec/60.0);split($5,LonD,"-");LDeg=LonD[1];LDec=LonD[2];Long=(LDeg+LDec/60.0);print $1,$2,$3,sum,Long,$6,$7,$8,$9,$10,$11,$12,$13,$14}' /tmp/YourInputFile
Nagarajan G |
|
#5
|
|||
|
|||
|
Quote:
Code:
awk '{
split($4,LatD,"-")
Deg=LatD[1]
Dec=LatD[2]
sum=(Deg+Dec/60.0)
split($5,LonD,"-")
LDeg=LonD[1]
LDec=LonD[2]
Long=(LDeg+LDec/60.0)
print $1,$2,$3,sum,Long,$6,$7,$8,$9,$10,$11,$12,$13,$14}
' /tmp/YourInputFile
|
|
#6
|
|||
|
|||
|
Hi every one
I would like to thanks you all, who ever help the others...!! First, I would like to thanks ennstate for his valuable coding he provide. With special thanks too, for ghostdog74, for making the coding more simpler looking..!! Thanks you all experts member's..!! Second, I have tried the coding and I have succeeded for doing the (first part of my) job. With slight modification on it..!! However, I have just add END statement before the PRINT command. And I saved the coding as a file, for example, as an abc.awk script file. That's all. ( I wrote this detail, to be useful for other to follow). But, there are some problems..!! The coding gave only the last line result..!! or only one result from this script..?? I will show the output from this coding later. NOW, This is my Input file: Quote:
And this the script after modification: Code:
awk '{
split($4,LatD,"-")
Deg=LatD[1]
Dec=LatD[2]
sum=(Deg+Dec/60.0)
split($5,LonD,"-")
LDeg=LonD[1]
LDec=LonD[2]
Long=(LDeg+LDec/60.0)
}
END {print $1,$2,$3,sum,Long,$6,$7,$8,$9,$10,$11,$12,$13,$14}
' /temp/allpun.out > addpun.out
PHP Code:
So, what I need NOW is to save all the result to the output file for the whole file NOT only for a single line. As it gave me ABOVE. For example, I want my final Output file look like this one: Quote:
And I appreciated, amm |
|
#7
|
|||
|
|||
|
Does this produce the expected results ?
Code:
awk '{
split($4,LatD,"-")
Deg=LatD[1]
Dec=LatD[2]
sum=(Deg+Dec/60.0)
split($5,LonD,"-")
LDeg=LonD[1]
LDec=LonD[2]
Long=(LDeg+LDec/60.0)
print $1,$2,$3,sum,Long,$6,$7,$8,$9,$10,$11,$12,$13,$14}
' /tmp/YourInputFile > /tmp/ProcessedOutput
Thanks Nagarajan G |
|||
| Google The UNIX and Linux Forums |