Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gawk and ubuntu 2

Status
Not open for further replies.

tini1208

Technical User
Feb 13, 2006
56
DE
hi all,

i have a big problem with my gawk. the programm is installed, i guess, because it works, when i'm using command line gawk.
now, i want to process more than one file in the same way and therefor, i want to write a script file.

the script looks like:

#! /usr/bin/gawk -f

set infile (i don't know, how to set more than one file e.g. *txt)

set outfile (how to use the first part of the infile and using a new ending e.g. *dat)

BEGIN {printf"%10.6f\t%10.6f\t%10.3f\t%10.3f\t%10.3f\t%10.3f\n", \
$1, $2, $3, $4, $5, sqrt($5*$5)}' infile > outfile



the script is executable (sudo chmod +x script).
i'm typing only the name of the script in the command line and nothing happens...no error, nothing.
can anyboby help me??
 
hi phv,

o.k.....how can i solve the problem???
 
sorry..i send the massage tooooo early.

what about this:

#BEGIN {printf"%10.6f\t%10.6f\t%10.3f\t%10.3f\t%10.3f\t%10.3f\n", \
$1, $2, $3, $4, $5, sqrt($5*$5)}#

but my problem is still....how can i process more than one file...like a batch!

where must i set the infile and outfile?
i know...these are really newbie questions :o(


 
One way (unix shell script):
awk '
FNR==1{if(out!="")close(out);out=FILENAME;sub(/txt$/,"dat",out}
{printf"%10.6f\t%10.6f\t%10.3f\t%10.3f\t%10.3f\t%10.3f\n",$1,$2,$3,$4,$5,sqrt($5*$5) > out}
' *txt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
yes...thanks a lot!!!
my script looks like this:

#! /bin/csh -f
foreach i (`ls *txt`)
echo $i
set outfile = $i:r.diff

awk'{printf"%10.6f\t%10.6f\t%10.3f\t%10.3f\t%10.3f\t%10.3f\n", \
$1, $2, $3, $4, $5, sqrt($5*$5)}' $i > $outfile
end

and it works very very well!!!!!!!!
thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top