For Programmers: Free Programming Magazines  


Home > Archive > AWK > June 2007 > Create files with awk varname









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Create files with awk varname
Atropo

2007-06-28, 6:57 pm

posted before on other thread, but seens nobody reads it anymore.

I have several files from the same day and i want to process only for
today

#!/usr/bin/ksh
TodayDate=`date +"%Y%m%d"`
export TodayDate
find . -name "${TodayDate}*.out" -exec awk -f busca.awk -v varfecha=
$TodayDate {} \;

where busca.awk has basically

/pattern/ {print "myfile" varfecha ".dat" }

i'd tried
{print "myfile" ENVIRON[TodayDate] ".dat"}


'coz I want to create myfile20070627.dat in both cases it creates
"myfile.dat"
what could i been doing wrong ??

Kenny McCormack

2007-06-28, 6:57 pm

In article <1183038357.991704.254110@u2g2000hsc.googlegroups.com>,
Atropo <lxvasquez@gmail.com> wrote:
>posted before on other thread, but seens nobody reads it anymore.


Because it was stupid then, and it's still stupid now.

Atropo

2007-06-28, 6:57 pm


Kenny McCormack ha escrito:
> In article <1183038357.991704.254110@u2g2000hsc.googlegroups.com>,
> Atropo <lxvasquez@gmail.com> wrote:
>
> Because it was stupid then, and it's still stupid now.


stupidity is something that usually you do when are new in something.
Really didn't believe those where your words, I know you are regular
at this group and I'm learning from your suggestions. but this is not
the case... Which would be an intelligent approximation?

Cesar Rabak

2007-06-28, 6:57 pm

Atropo escreveu:
> posted before on other thread, but seens nobody reads it anymore.
>
> I have several files from the same day and i want to process only for
> today
>
> #!/usr/bin/ksh
> TodayDate=`date +"%Y%m%d"`
> export TodayDate
> find . -name "${TodayDate}*.out" -exec awk -f busca.awk -v varfecha=
> $TodayDate {} \;
>
> where busca.awk has basically
>
> /pattern/ {print "myfile" varfecha ".dat" }
>
> i'd tried
> {print "myfile" ENVIRON[TodayDate] ".dat"}
>
>
> 'coz I want to create myfile20070627.dat in both cases it creates
> "myfile.dat"
> what could i been doing wrong ??
>

Something very odd.

I tried:

$p$gTodayDate=`date.exe +"%Y%m%d"`

Just to be sure:

$p$gecho $TodayDate
20070628

$p$gecho 1 | awk -v varfecha=$TodayDate '{print "myfile" varfecha ".dat"}'
myfile20070628.dat

HTH

--
Cesar Rabak
Atropo

2007-06-28, 6:57 pm


Cesar Rabak ha escrito:
> Atropo escreveu:
> Something very odd.
>
> I tried:
>
> $p$gTodayDate=`date.exe +"%Y%m%d"`
>
> Just to be sure:
>
> $p$gecho $TodayDate
> 20070628
>
> $p$gecho 1 | awk -v varfecha=$TodayDate '{print "myfile" varfecha ".dat"}'
> myfile20070628.dat
>
> HTH
>
> --
> Cesar Rabak


Thanks a lot Cesar, it's now when i see the stupidity that Kenny
refers to. in my original script i have {print var > "myfile.txt"}.
but it was processing several files an only the output from the last
one was on the file then I put {print var >> "myfile.txt"} so i guess
now that as there is not myfile.txt then it can't append. .. Does
{print >> "myfile"} creates the file or it just for append?

Cesar Rabak

2007-06-28, 6:57 pm

Atropo escreveu:
> Cesar Rabak ha escrito:
>
> Thanks a lot Cesar, it's now when i see the stupidity that Kenny
> refers to. in my original script i have {print var > "myfile.txt"}.
> but it was processing several files an only the output from the last
> one was on the file then I put {print var >> "myfile.txt"} so i guess
> now that as there is not myfile.txt then it can't append. .. Does
> {print >> "myfile"} creates the file or it just for append?
>

In my SO '{print >> "myfile"}' creates the file. . .

--
Cesar Rabak

Vassilis

2007-06-28, 6:57 pm


Atropo :
> posted before on other thread, but seens nobody reads it anymore.
>
> I have several files from the same day and i want to process only for
> today
>
> #!/usr/bin/ksh
> TodayDate=`date +"%Y%m%d"`
> export TodayDate
> find . -name "${TodayDate}*.out" -exec awk -f busca.awk -v varfecha=
> $TodayDate {} \;


I can't see why the above wouldn't work. Maybe your awk supports -v
before any script (wild guess).

>
> where busca.awk has basically
>
> /pattern/ {print "myfile" varfecha ".dat" }


This just prints *to stdout* "myfile20070628.dat"

>
> i'd tried
> {print "myfile" ENVIRON[TodayDate] ".dat"}


You probably meant { print "myfile" ENVIRON["TodayDate"] ".dat" }

>
>
> 'coz I want to create myfile20070627.dat in both cases it creates
> "myfile.dat"
> what could i been doing wrong ??


Creating a new file (that is, if a file with same name exists, it gets
its contents erased):

awk -v today=$(date +'%Y%m%d') 'BEGIN { print "hello" > ("myfile"
today ".dat") }'

Use of parens is strongly suggested.

Appending to a file (or creating a new one, if there isn't any):

awk -v today=$(date +'%Y%m%d') 'BEGIN { print "hello" >> ("myfile"
today ".dat") }'

HTH

Vassilis

Atropo

2007-06-28, 6:57 pm


Vassilis ha escrito:
> Atropo :
>
> I can't see why the above wouldn't work. Maybe your awk supports -v
> before any script (wild guess).
>
>
> This just prints *to stdout* "myfile20070628.dat"
>
>
> You probably meant { print "myfile" ENVIRON["TodayDate"] ".dat" }
>
>
> Creating a new file (that is, if a file with same name exists, it gets
> its contents erased):
>
> awk -v today=$(date +'%Y%m%d') 'BEGIN { print "hello" > ("myfile"
> today ".dat") }'
>
> Use of parens is strongly suggested.
>
> Appending to a file (or creating a new one, if there isn't any):
>
> awk -v today=$(date +'%Y%m%d') 'BEGIN { print "hello" >> ("myfile"
> today ".dat") }'
>
> HTH
>
> Vassilis


Thanks Vassilis, I just put the parenthesis and it works.. maybe
'coz is an old nawk on an old AIX

Ed Morton

2007-06-28, 9:57 pm

Cesar Rabak wrote:
> Atropo escreveu:
>
> In my SO '{print >> "myfile"}' creates the file. . .


print > "myfile" would create the file if it doesn't exist, and start
overwriting the file if it does.

print >> "myfile" would create the file if it doesn't exist, and start
appending to the file if it does.

Ed.
Jobbiejabber

2007-06-29, 9:15 pm

http://www.thetubetech.com/Play?watch=1673286
Ed Morton

2007-06-30, 7:56 am

Atropo wrote:
> Kenny McCormack ha escrito:
>
>
>
> stupidity is something that usually you do when are new in something.
> Really didn't believe those where your words, I know you are regular
> at this group and I'm learning from your suggestions. but this is not
> the case... Which would be an intelligent approximation?
>


I can't speak for anyone else and I don't know if this is what Kenny was
getting at, but in case it sheds some light:

I was ignoring the question because you posted a mixture of shell+awk
where the awk portion you posted:

> where busca.awk has basically
>
> /pattern/ {print "myfile" varfecha ".dat" }
>
> i'd tried
> {print "myfile" ENVIRON[TodayDate] ".dat"}


clearly could not produce the result you were claiming to get:

> 'coz I want to create myfile20070627.dat in both cases it creates
> "myfile.dat"


so in essence you posted a script that didn't exist and stated that it
produced an output it couldn't produce instead of the output you
expected and then asked us why. There's just no answer to that....

Ed.


Atropo

2007-06-30, 7:57 am

On 29 jun, 08:31, Ed Morton <mor...@lsupcaemnt.com> wrote:
> Atropo wrote:
>
>
>
>
>
> I can't speak for anyone else and I don't know if this is what Kenny was
> getting at, but in case it sheds some light:
>
> I was ignoring the question because you posted a mixture of shell+awk
> where the awk portion you posted:
>
>
>
>
> clearly could not produce the result you were claiming to get:
>
>
> so in essence you posted a script that didn't exist and stated that it
> produced an output it couldn't produce instead of the output you
> expected and then asked us why. There's just no answer to that....
>
> Ed.- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -


Ed really appreciate your time to show me a "badly explained case".
this really help me to improve the way to post.

Kenny McCormack

2007-06-30, 7:57 am

In article < IsmdnRrUnM0vlBjbnZ2dnUVZ_qOpnZ2d@comcast
.com>,
Ed Morton <morton@lsupcaemnt.com> wrote:
....
>so in essence you posted a script that didn't exist and stated that it
>produced an output it couldn't produce instead of the output you
>expected and then asked us why. There's just no answer to that....


Well put, sir!

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com