The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-16-2008
amm amm is offline
Registered User
 

Join Date: Jan 2008
Posts: 7
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
Reply With Quote
Forum Sponsor
  #2  
Old 01-16-2008
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
1.
Code:
grep -h "[0-9]" *.PUN > allpun.out
Check out man grep to see if your version of grep supports the -h flag.

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
If not, can you show us the expected output on a sample input.
Reply With Quote
  #3  
Old 01-16-2008
amm amm is offline
Registered User
 

Join Date: Jan 2008
Posts: 7
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
Reply With Quote
  #4  
Old 01-16-2008
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
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
Thanks
Nagarajan G
Reply With Quote
  #5  
Old 01-16-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by ennstate View Post
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
Thanks
Nagarajan G
Its only clumsy when you lump them up into one long mess. anyway, its not a competition for one-liners
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
Reply With Quote
  #6  
Old 01-17-2008
amm amm is offline
Registered User
 

Join Date: Jan 2008
Posts: 7
Smile succeed

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

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
And this the output result from this script:
PHP Code:
dd2.awk
   24.8923 40.768 
How do I modify this coding to print all the calculated results for the whole file ABOVE mentioned..?

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:
960109 914 4.54 25.1535 40.839 14.83 2.81 12 335116.5 0.26 6.8 81.7 D1

940129 559 37.02 24.4822 39.8632 0.86 1.99 17 151 9.0 0.07 0.2 0.4 B1

940130 1047 38.93 24.8982 40.7385 9.52 2.89 20 321 93.9 0.17 1.6 28.7 D1

940131 843 37.78 24.8923 40.7680 5.19 2.88 17 322 96.4 0.21 15.9 49.9 D1
Any more help and experience are welcome..

And I appreciated,
amm
Reply With Quote
  #7  
Old 01-17-2008
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
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
Also as END statement will be executed only once so it produces only the result of the last line in this case.But am not sure why it does print only the two fields as in your output.

Thanks
Nagarajan G
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0