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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert to *.js file 1

Status
Not open for further replies.

FedoEx

Technical User
Oct 7, 2008
49
US
Input file
Code:
1300483198 -4.60508
1300483199 -4.60825
1300483200 -4.60691
1300483201 -4.60581
1300483202 -4.60806
1300483203 -4.60747
1300483205 -4.60788
1300483206 -4.60704
1300483207 -4.60843
1300483208 -4.60675
1300483209 -4.60827
1300483210 -4.60721
1300483211 -4.60807
1300483212 -4.60778
1300483213 -4.60902
1300483215 -4.5526
1300483216 -4.68561
1300483217 -4.47417
1300483218 -4.50509

My code so far

Code:
#!/bin/awk                                                                                      
 BEGIN{
     print "function MyData(){ \n return \42\42+\n\42 Date,A, \\n  \42+\
        " }
 {printf("%s", strftime("\42%Y/%m/%d ",$1));
  printf("%s", strftime("%H:%M:%S,",$1));
  print $2 "\\n\42+"     }
  END{  print "}"                  }

Desired output

Code:
function MytData(){
 return ""+
" Date,A, \n  "+
"2011/03/18 16:19:58,-4.60508\n"+
"2011/03/18 16:19:59,-4.60825\n"+
"2011/03/18 16:20:00,-4.60691\n"+
"2011/03/18 16:20:01,-4.60581\n"+
"2011/03/18 16:20:02,-4.60806\n"+
"2011/03/18 16:20:03,-4.60747\n"+
"2011/03/18 16:20:05,-4.60788\n"+
"2011/03/18 16:20:06,-4.60704\n"+
"2011/03/18 16:20:07,-4.60843\n"+
"2011/03/18 16:20:08,-4.60675\n"+
"2011/03/18 16:20:09,-4.60827\n"+
"2011/03/18 16:20:10,-4.60721\n"+
"2011/03/18 16:20:11,-4.60807\n"+
"2011/03/18 16:20:12,-4.60778\n"+
"2011/03/18 16:20:13,-4.60902\n"+
"2011/03/18 16:20:15,-4.5526\n"+
"2011/03/18 16:20:16,-4.68561\n"+
"2011/03/18 16:20:17,-4.47417\n"+
"2011/03/18 16:20:18,-4.50509\n";
}
My code terminates all the lines with [red]+[/red].
I need to get rid of that last [red]+[/red] and replace it with [red];[/red].

Can you also if you can provide with alternative approach to this problem.
Thaks.
 
Well, don't print it then, but print an ; instead...

your code
[tt]print $2 "\\n\42[red]+[/red]"[/tt]

should be
[tt]print $2 "\\n\42[red];[/red]"[/tt]

HTH,

p5wizard
 
I need only the last line to end with [red];[/red]
All the rest should end with [red]+[/red].
 
Is this what you want?
Code:
 BEGIN{
     printf("%s", "function MyData(){ \n return \42\42+\n\42 Date,A, \\n  \42\
        ") }
 {print "+"
  printf("%s", strftime("\42%Y/%m/%d ",$1));
  printf("%s", strftime("%H:%M:%S,",$1));
  printf("%s", $2 "\\n\42")     }
  END{ print ";";  print "}" }

CaKiwi
 
Yes.
That is exactly what I need.
Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top