Simple, yes, but it took me a few minutes on Google to remember the awk syntax. Unix is powerful, but it isn't intuitive.<br><br>David<br><br><div><span class="gmail_quote">On 8/11/06, <b class="gmail_sendername">maning sambale
</b> &lt;<a href="mailto:emmanuel.sambale@gmail.com">emmanuel.sambale@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
David,<br><br>thank you!&nbsp;&nbsp;that's the one I need (for now).&nbsp;&nbsp;Funny how simple it is.<br>Another funny anecdote, about a year ago I passed by our GIS lab and<br>saw a girl editing very large ascii file (mouse click, edit, edit,
<br>save, next line) much the same as my files I'm manipulating right now.<br> I asked her there might be a better way in doing this.&nbsp;&nbsp;She said it's<br>the only way her instructor and the lab technician thought them. :)<br>
<br>cheers,<br><br>Maning<br><br>On 8/10/06, David Finlayson &lt;<a href="mailto:david.p.finlayson@gmail.com">david.p.finlayson@gmail.com</a>&gt; wrote:<br>&gt; Try this to print column 1 and 3. I think it will work on all of your files
<br>&gt; no matter how many spaces are in between:<br>&gt;<br>&gt; cat file | awk '{print $1, $3}'<br>&gt;<br>&gt; David<br>&gt;<br>&gt;<br>&gt; On 8/9/06, maning sambale &lt;<a href="mailto:emmanuel.sambale@gmail.com">emmanuel.sambale@gmail.com
</a>&gt; wrote:<br>&gt; &gt; David &amp; Kevin,<br>&gt; &gt;<br>&gt; &gt; Yes, python or perl would be great.&nbsp;&nbsp;But what I need right now is a<br>&gt; &gt; quick (maybe dirty) approach.&nbsp;&nbsp;I do intend to study python as I've
<br>&gt; &gt; heard a lot about it.&nbsp;&nbsp;But not this time, I'm trying to study Linux<br>&gt; &gt; tools the &quot;modular way&quot;:)<br>&gt; &gt;<br>&gt; &gt; Cheers,<br>&gt; &gt;<br>&gt; &gt; Maning<br>&gt; &gt;<br>&gt; &gt; On 8/8/06, Slover, Kevin &lt;
<a href="mailto:kslover@dewberry.com">kslover@dewberry.com</a>&gt; wrote:<br>&gt; &gt; &gt; Maning,<br>&gt; &gt; &gt;&nbsp;&nbsp; As David says, python or perl are used now for manipulating text<br>&gt; &gt; &gt; files.&nbsp;&nbsp;I have done several quick scripts for doing this with Perl
<br>&gt; &gt; &gt; (thanks David for the python script, bout time I learn to use it).&nbsp;&nbsp;A<br>&gt; &gt; &gt; basic perl script would look like this (and note, my Perl is not great,<br>&gt; &gt; &gt; and am sure there are many other ways to do this) :
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Explanation:&nbsp;&nbsp;Files.txt is a ls/dir listing of the wanted files to<br>&gt; &gt; &gt; combine.&nbsp;&nbsp;Then, the script reads in each file, stripping any sort of<br>&gt; &gt; &gt; header information from the columns, and outputting everything into one
<br>&gt; &gt; &gt; file.&nbsp;&nbsp;Fairly simple, and a quick search on the web for file<br>&gt; &gt; &gt; manipulation using Perl will come up with probably a better explanation.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; $in_file = &quot;
Files.txt&quot;;<br>&gt; &gt; &gt; $out_file = &quot;outfile.txt&quot;;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; open (INFILE, $in_file) || die &quot;INFILE&quot;;<br>&gt; &gt; &gt; open (OUTFILE, &quot;&gt;$out_file&quot;) || die &quot;OUTFILE&quot;;
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; @infiles = &lt;INFILE&gt;;<br>&gt; &gt; &gt; close(INFILE);<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; print OUTFILE &quot;z,x,y\n&quot;;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; foreach $in_files (@infiles)
<br>&gt; &gt; &gt; {<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; open (INFILE1, $in_files) || die &quot;Cannot open $in_files&quot;;<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (&lt;INFILE1&gt;)<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt; &gt; &gt;
<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chomp($_);<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ($x, $y, $z) = split ',',$_;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($x != x) {<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print OUTFILE &quot;$z,$x,$y\n&quot;; }
<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close(INFILE1);<br>&gt; &gt; &gt; }<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; close(OUTFILE);<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Kevin Slover
<br>&gt; &gt; &gt; Coastal / GIS Specialist<br>&gt; &gt; &gt; 2872 Woodcock Blvd Suite 230<br>&gt; &gt; &gt; Atlanta GA 30341<br>&gt; &gt; &gt; (P) 678-530-0022<br>&gt; &gt; &gt; (F) 678-530-0044<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; -----Original Message-----
<br>&gt; &gt; &gt; From: <a href="mailto:grassuser-bounces@grass.itc.it">grassuser-bounces@grass.itc.it</a><br>&gt; &gt; &gt; [mailto: <a href="mailto:grassuser-bounces@grass.itc.it">grassuser-bounces@grass.itc.it</a>] On Behalf Of maning sambale
<br>&gt; &gt; &gt; Sent: Tuesday, August 08, 2006 12:12 AM<br>&gt; &gt; &gt; To: <a href="mailto:grassuser@grass.itc.it">grassuser@grass.itc.it</a><br>&gt; &gt; &gt; Subject: [GRASS-user] combine &amp; edit multiple text files
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Hi!<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; I have a number of ascii files downloaded from ASTR fire project from<br>&gt; &gt; &gt; the ESA Ionia showing monthly fire incidences from 1996-2006.&nbsp;&nbsp;I
<br>&gt; &gt; &gt; intend to combine all these files, remove unwanted columns and get the<br>&gt; &gt; &gt; records from my current region/study area only. All records combined<br>&gt; &gt; &gt; is 929,155 records!&nbsp;&nbsp;My guess is I need to use the cat, cut, awk
<br>&gt; &gt; &gt; commands.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Challenge: the files have different record formating<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; file 1 is like this (take note of the space as the delimiter):<br>&gt; &gt; &gt;
<br>&gt; &gt; &gt; Date&nbsp;&nbsp; Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lat&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lon&nbsp;&nbsp;&nbsp;&nbsp; NDVI&nbsp;&nbsp;Station<br>&gt; &gt; &gt; 020201 032428.163&nbsp;&nbsp;-38.379&nbsp;&nbsp;-66.334 -.-- ESR<br>&gt; &gt; &gt; 020201 032428.163&nbsp;&nbsp; -38.375&nbsp;&nbsp;-66.323 -.-- ESR<br>&gt; &gt; &gt; 020201 
032428.312&nbsp;&nbsp;-38.378&nbsp;&nbsp;-66.359 -.-- ESR<br>&gt; &gt; &gt; 020201 032428.312&nbsp;&nbsp;-38.374&nbsp;&nbsp;-66.348 -.-- ESR<br>&gt; &gt; &gt; 020201 032428.312&nbsp;&nbsp;-38.371&nbsp;&nbsp;-66.337 -.-- ESR<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; file 2 looks like this:
<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Orbit&nbsp;&nbsp;Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lat<br>&gt;&nbsp;&nbsp; Lon<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 20030101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4384&nbsp;&nbsp;&nbsp;&nbsp; 81704.016&nbsp;&nbsp;&nbsp;&nbsp;19.364&nbsp;&nbsp;-155.103<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 20030101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4384&nbsp;&nbsp;&nbsp;&nbsp; 81704.164&nbsp;&nbsp;&nbsp;&nbsp;19.373
&nbsp;&nbsp;-155.105<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 20030101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4384&nbsp;&nbsp;&nbsp;&nbsp; 81704.164&nbsp;&nbsp;&nbsp;&nbsp;19.375&nbsp;&nbsp;-155.096<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 20030101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4385&nbsp;&nbsp;&nbsp;&nbsp;100833.648&nbsp;&nbsp;&nbsp;&nbsp;56.638&nbsp;&nbsp; 161.281<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 20030101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4386&nbsp;&nbsp;&nbsp;&nbsp;130756.352
&nbsp;&nbsp; -20.340&nbsp;&nbsp; 134.099<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; I only need the columns for date, time, lat, lon<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Here's what I did:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; #combine all file (monthly)
<br>&gt; &gt; &gt; cat 9904ESA01.FIRE 9905ESA01.FIRE 9906ESA01.FIRE 9907ESA01.FIRE<br>&gt; &gt; &gt; 9908ESA01.FIRE ... &gt; test<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; # cut only desired columns (1_4) delimeiter is spac ' '
<br>&gt; &gt; &gt; cut -d' ' -f1 test &gt; 1<br>&gt; &gt; &gt; cut -d' ' -f2 test &gt; 2<br>&gt; &gt; &gt; cut -d' ' -f3 test &gt; 3<br>&gt; &gt; &gt; cut -d' ' -f4 test &gt; 4<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; # combine all columns
<br>&gt; &gt; &gt; paste 1 2 3 4 &gt; test5<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; example output:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; 021231 223941.761&nbsp;&nbsp; 11.035&nbsp;&nbsp; -5.016 -.-- ESR<br>&gt; &gt; &gt; 021231 224005.303&nbsp;&nbsp; 12.226
&nbsp;&nbsp; -6.243 -.-- ESR<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 20030101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4380&nbsp;&nbsp;&nbsp;&nbsp; 25934.057&nbsp;&nbsp; -37.022&nbsp;&nbsp; -69.589<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 20030101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4382&nbsp;&nbsp;&nbsp;&nbsp; 45951.090&nbsp;&nbsp;&nbsp;&nbsp; 33.005&nbsp;&nbsp;-110.772<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; The problem is for the file example 1, lat and lon columns contain
<br>&gt; &gt; &gt; spaces other than the delimiter example &quot; -38.00&quot; while another is<br>&gt; &gt; &gt; &quot;120.00&quot;&nbsp;&nbsp;In the file2 example, more spaces are there.&nbsp;&nbsp;I think I need<br>&gt; &gt; &gt; to process different file formats separately but how do I solve the
<br>&gt; &gt; &gt; problem for spaces in the lat/lon columns?<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; One last question how do I get the records for my current region only?<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; north:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20:00:
01.49976N<br>&gt; &gt; &gt; south:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5:00:01.499767N<br>&gt; &gt; &gt; west:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 115:00:01.5012E<br>&gt; &gt; &gt; east:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 130:00:01.501193E<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; I'm starting to understand awk (reading the gawk manual right now) but
<br>&gt; &gt; &gt; may take a while to get do something magical.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Thanks!<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Maning<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; --<br>&gt; &gt; &gt;<br>&gt; |---------|----------------------------------------------------------|
<br>&gt; &gt; &gt; | __.-._&nbsp;&nbsp;|&quot;Ohhh. Great warrior. Wars not make one great.&quot; -Yoda&nbsp;&nbsp;&nbsp;&nbsp; |<br>&gt; &gt; &gt; | '-._&quot;7' |&quot;Freedom is still the most radical idea of all&quot; -N.Branden|<br>&gt; &gt; &gt; |&nbsp;&nbsp;/'.-c&nbsp;&nbsp;|Linux registered user #402901, 
<a href="http://counter.li.org/">http://counter.li.org/</a>&nbsp;&nbsp;&nbsp;&nbsp; |<br>&gt; &gt; &gt; |&nbsp;&nbsp;|&nbsp;&nbsp;/T&nbsp;&nbsp;|http://esambale.wikispaces.com|<br>&gt; &gt; &gt; | _)_/LI<br>&gt; &gt; &gt;<br>&gt; |http://www.geocities.com/esambale/philbiodivmap/philbirds.html
<br>&gt;&nbsp;&nbsp; |<br>&gt; &gt; &gt;<br>&gt; |---------|----------------------------------------------------------|<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; _______________________________________________<br>&gt; &gt; &gt; grassuser mailing list
<br>&gt; &gt; &gt; <a href="mailto:grassuser@grass.itc.it">grassuser@grass.itc.it</a><br>&gt; &gt; &gt; <a href="http://grass.itc.it/mailman/listinfo/grassuser">http://grass.itc.it/mailman/listinfo/grassuser</a><br>&gt; &gt; &gt;
<br>&gt; &gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; --<br>&gt; &gt;<br>&gt; |---------|----------------------------------------------------------|<br>&gt; &gt; | __.-._&nbsp;&nbsp;|&quot;Ohhh. Great warrior. Wars not make one great.&quot; -Yoda&nbsp;&nbsp;&nbsp;&nbsp; |
<br>&gt; &gt; | '-._&quot;7' |&quot;Freedom is still the most radical idea of all&quot; - N.Branden|<br>&gt; &gt; |&nbsp;&nbsp;/'.-c&nbsp;&nbsp;|Linux registered user #402901, <a href="http://counter.li.org/">http://counter.li.org/</a>&nbsp;&nbsp;&nbsp;&nbsp; |
<br>&gt; &gt; |&nbsp;&nbsp;|&nbsp;&nbsp;/T&nbsp;&nbsp;|http://esambale.wikispaces.com|<br>&gt; &gt; | _)_/LI<br>&gt; |http://www.geocities.com/esambale/philbiodivmap/philbirds.html<br>&gt;&nbsp;&nbsp; |<br>&gt; &gt;<br>&gt; |---------|----------------------------------------------------------|
<br>&gt; &gt;<br>&gt; &gt; _______________________________________________<br>&gt; &gt; grassuser mailing list<br>&gt; &gt; <a href="mailto:grassuser@grass.itc.it">grassuser@grass.itc.it</a><br>&gt; &gt; <a href="http://grass.itc.it/mailman/listinfo/grassuser">
http://grass.itc.it/mailman/listinfo/grassuser</a><br>&gt; &gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; --<br>&gt; David Finlayson<br><br><br>--<br>|---------|----------------------------------------------------------|<br>| __.-._&nbsp;&nbsp;|&quot;Ohhh. Great warrior. Wars not make one great.&quot; -Yoda&nbsp;&nbsp;&nbsp;&nbsp; |
<br>| '-._&quot;7' |&quot;Freedom is still the most radical idea of all&quot; -N.Branden|<br>|&nbsp;&nbsp;/'.-c&nbsp;&nbsp;|Linux registered user #402901, <a href="http://counter.li.org/">http://counter.li.org/</a>&nbsp;&nbsp;&nbsp;&nbsp; |<br>|&nbsp;&nbsp;|&nbsp;&nbsp;/T&nbsp;&nbsp;|http://esambale.wikispaces.com|
<br>| _)_/LI&nbsp;&nbsp;|http://www.geocities.com/esambale/philbiodivmap/philbirds.html&nbsp;&nbsp; |<br>|---------|----------------------------------------------------------|<br><br>_______________________________________________<br>grassuser mailing list
<br><a href="mailto:grassuser@grass.itc.it">grassuser@grass.itc.it</a><br><a href="http://grass.itc.it/mailman/listinfo/grassuser">http://grass.itc.it/mailman/listinfo/grassuser</a><br></blockquote></div><br><br clear="all">
<br>-- <br>David Finlayson