If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help with Shell Script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-04, 13:48
malinut89 malinut89 is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
Help with Shell Script

Hi,

I have three large data files that need alteration. Each consists of -9999 (null data) entries and 5 or 6 digit numeric entries (104625, 99841, etc). I would like to divide the numeric entries by 100000 while allowing the null data entries to remain intact. There is also six rows of "header information" that needs to be skipped over as the alteration is performed.

A small portion of one file:

ncols 1484
nrows 1680
xllcorner -117.231250
yllcorner 41.98958333
cellsize 0.00416667
nodata_value -9999
-9999 -9999 -9999 -9999 -9999 -9999 103456 102321 109884 102223
-9999 -9999 -9999 -9999 -9999 -9999 99667 94557 103445 103224

and so on...

i would like to have:

ncols 1484
nrows 1680
xllcorner -117.231250
yllcorner 41.98958333
cellsize 0.00416667
nodata_value -9999
-9999 -9999 -9999 -9999 -9999 -9999 1.03456 1.02321 1.09884 1.02223
-9999 -9999 -9999 -9999 -9999 -9999 0.99667 0.94557 1.03445 1.03224

Thank you in advance for your help!
Reply With Quote
  #2 (permalink)  
Old 11-16-04, 15:12
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi malinut89,
try this :

#!/bin/ksh

I="mydata.org" # your inputfile
O="mydata.new" # your outputfile
> $O

cat $I | awk ' BEGIN { FS=" "; i=0}
{
#### maximum values per row
max = 10

#### read the nodata_value
if ( $1 == "nodata_value" )
{
ndv = $2
}
i=i+1
#### write the the first six rows as header to new file
if (i < 7)
{
print $0 > "mydata.new"
}
else
{
x=0
while (x != max)
{
x=x+1
#### null data entries to remain intact
if ( $x != ndv )
{
$x = $x / 100000
}
}
x=0
while (x != max)
{
x=x+1
printf ("%s " ,$x) > "mydata.new"
}
printf ( "\n") > "mydata.new"

}
}'
__________________
Greetings from germany
Peter F.
Reply With Quote
  #3 (permalink)  
Old 11-16-04, 19:03
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
nawk -f mali.awk myFiles*

here's mali.awk:
Code:
BEGIN {
  _div="100000"
  _nul="-9999"
  PATnum="[-.0-9]"
}

FNR=1 { out= FILENAME "_new"}

$1 ~ PATnum {
   for(i=1; i <= NF; i++)
     $i = ( $i == _nul ) ? _nul : sprintf("%.5f", $i / _div )
   print >> out
}
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On