--- Taylor Lewick <[EMAIL PROTECTED]> wrote:
> Hi, I have the following one liner which works great in a shell script. I have a
>comma
> delimited text file with the same number of rows.
> I want to add the date in YYYY-MM-DD format to every line...
>
> I was doing this..
> cat $file | awk '{print $0 "," "'$fdate'"}' >>$new_file
>
> Works great
>
> Unfortunately when I add that to perl in backticks for the system to execute,
> It blows up on the quotes between $0 (the whole line), the comma, and the date
>variable.
>
> In perl, I know I could do...
> $fdate=`date
> open (FILE, ">/newfile");
> @file=`cat $oldfile`
> foreach $item(@file) {
> chomp $item;
> print FILE "$item,$fdate\n";
> }
> close (FILE);
>
> However, it seems like such a waste to turn an elegant one line into 8 lines of code
>
> So how can I make that one liner work, I've tried backslashing the quotes, using
>single quotes,
> and everytime awk blows up at me?
> Thanks much,
> Taylor
Taylor,
If you're trying to do this in a one-liner, pure Perl (assuming that I understood your
question
correctly), the the following should do the trick:
$ perl -p -e
'@t=localtime;$t[4]++;$t[5]+=1900;s/$/sprintf(",%4d-%02d-%02d",@t[5,4,3])/e'
oldFile.txt >> newFile.txt
Yeah, it's big and ugly and assumes that you are appending ",YYYY-MM-DD". Somehow,
though, I
suspect that I may have misunderstood your intent...
Cheers,
Curtis "Ovid" Poe
=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A
__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]