Code Comments
Programming Forum and web based access to our favorite programming groups.> Hi, > > thanks for your previous help, pk and Stephane. > > Now I have the problem to append a line > to my 1000 model files *.mod > which all have the entry > solve; > as their hitherto last line. > The last line (after the solve; line) shall now look like > printf : "%s %5i %5i %5i %5i %10.5f %10.5f \n", *, N, M, IERR, ITER, F, _ solve_time >> TABLE.TEX; > > where the * in this line should be the * from *.mod above. > > Thanks again > Dieter -- Dieter Kraft Munich University of Applied Sciences Department of Mechanical Engineering dieter.kraft@hm.edu www.lrz-muenchen.de/~dkraft
Post Follow-up to this messageOn 3/27/2008 2:10 AM, Dieter Kraft wrote: Assuming I don't need any context from a previous post: base=FILENAME sub(/.mod$/,"",base) printf "%s %5i %5i %5i %5i %10.5f %10.5f \n", base, N, M, ... Ed.
Post Follow-up to this messagepk wrote:
> Dieter Kraft wrote:
>
>
> If I understand it correctly, you have 1000 files whose name ends in .mod,
> the last line of each file being "solve;". For each file, you want to
> append a line after the "solve;" line, and, in this new line, the "*"
> should be replaced with the filename (without the .mod).
> Note that, If I understand correctly, the information that the last line i
s
> currently "solve;" is superfluous, since you want to append the new line a
t
> the end anyway.
>
> If this is correct, then
>
> cd /dir/with/mod/files
> for name in *.mod; do
>
> # basename without suffix
> bname=${name%.mod}
>
> # line to append; must be all on a single line
> line="printf : \"%s %5i %5i %5i %5i %10.5f %10.5f \\n\", $bname, N, M,
> IERR, ITER, F, _solve_time >> TABLE.TEX;"
>
> # appends the new line at the end of the file
> printf "%s\n", "$line" >> "$name"
> done
>
>
>
Thanks, it does what I (respectively ampl www.ampl.com) want if I do two
changes
line="printf : \"%s %5i %5i %5i %5i %10.5f %10.5f \\n\", ' $bname ', N,
$bname as a string and
printf "%s\n" "$line" >> "$name"
no comma
Thanks again
Dieter
--
Dieter Kraft
Munich University of Applied Sciences
Department of Mechanical Engineering
dieter.kraft@hm.edu
www.lrz-muenchen.de/~dkraft
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.