|
Home > Archive > Unix Shell > November 2007 > tricky sed problem
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 |
tricky sed problem
|
|
| zmrzlina@volny.cz 2007-11-30, 1:24 pm |
| Hi,
line="HFC125MMR= 0.000e+00,"
sed "/&RUNCNST/ a\
$line
" CNTLATM >CNTLATM.tmp
What I want is to insert the above string $line into a text file below
the value &RUNCNST
What I have above works EXCEPT that I need it to offset $line by one
whitespace.
i.e.
The output from above is
[snip]
&RUNCNST
HFC125MMR= 0.000e+00,
MPARWTR=1.0000e-03,
ANVIL_FACTOR=2.5000,
[snip]
What I want it the above, except for one white space in front of
HFC125MMR. I have tried various combinations using \ (like \$line,
but that just writes $line as a string instead a variable) but I can't
seem to get it right.
Any help is much appreciated. I have spent a long time googling and
trying to do this on my own.
Thank you
| |
| Maxwell Lol 2007-11-30, 7:23 pm |
| zmrzlina@volny.cz writes:
> Hi,
>
> line="HFC125MMR= 0.000e+00,"
> sed "/&RUNCNST/ a\
> $line
> " CNTLATM >CNTLATM.tmp
try:
line="HFC125MMR= 0.000e+00,"
sed "/&RUNCNST/ a\
\ $line
" CNTLATM >CNTLATM.tmp
| |
| Ed Morton 2007-11-30, 7:23 pm |
|
On 11/30/2007 1:05 PM, zmrzlina@volny.cz wrote:
> Hi,
>
> line="HFC125MMR= 0.000e+00,"
> sed "/&RUNCNST/ a\
> $line
> " CNTLATM >CNTLATM.tmp
>
> What I want is to insert the above string $line into a text file below
> the value &RUNCNST
>
> What I have above works EXCEPT that I need it to offset $line by one
> whitespace.
> i.e.
> The output from above is
>
> [snip]
> &RUNCNST
> HFC125MMR= 0.000e+00,
> MPARWTR=1.0000e-03,
> ANVIL_FACTOR=2.5000,
> [snip]
>
> What I want it the above, except for one white space in front of
> HFC125MMR. I have tried various combinations using \ (like \$line,
> but that just writes $line as a string instead a variable) but I can't
> seem to get it right.
>
> Any help is much appreciated. I have spent a long time googling and
> trying to do this on my own.
>
> Thank you
>
For anything but simple substituions, use awk rather than sed:
line="HFC125MMR= 0.000e+00,"
awk -v line="$line" '{print} /&RUNCNST/{ printf " %s\n",line }' CNTLATM >CNTLATM.tmp
Ed.
| |
| Edward Rosten 2007-11-30, 7:23 pm |
| On Nov 30, 1:09 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> For anything but simple substituions, use awk rather than sed:
In general, except that (portably), awk has strictly regular
expressions (ie no backreferences), where as sed does not.
-Ed
|
|
|
|
|