Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: insert line...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 2206 of 2241
Post > Topic >>

Re: insert line once again

by Dieter Kraft <kraft@[EMAIL PROTECTED] > Mar 27, 2008 at 06:21 PM

pk wrote:
> Dieter Kraft wrote:
> 
>>> 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.
> 
> 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
is
> currently "solve;" is superfluous, since you want to append the new line
at
> 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@[EMAIL PROTECTED]





 3 Posts in Topic:
insert line once again
Dieter Kraft <kraft@[E  2008-03-27 08:10:38 
Re: insert line once again
Ed Morton <morton@[EMA  2008-03-27 08:04:57 
Re: insert line once again
Dieter Kraft <kraft@[E  2008-03-27 18:21:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 3:37:29 CDT 2008.