0

Even though I have checked the relevant questions about this, I could not find any solution. I think my problem is very simple, but I cant fix it lack of knowledge.

$statistics dscf parallel $2e-ints_shell_statistics file=DSCF-par-stat $parallel_parameters maxtask=4000 maxdisk=0 dynamic_fraction=0.300000 $pardft memdiv=1 

I want to add these multiple lines to a text file after when it sees "unix" word. So my code is something like this.

sed -i "/unix/a \\ $statistics dscf parallel \\ $2e-ints_shell_statistics file=DSCF-par-stat \\ $parallel_parameters \\ maxtask=4000 \\ maxdisk=0 \\ dynamic_fraction=0.300000 \\ $pardft \\ memdiv=1 \\ " control 

control is my output file. because of the $ sign the output lacks some parts of this insertion which looks like this.

$operating system unix dscf parallel e-ints_shell_statistics file=DSCF-par-stat maxtask=4000 maxdisk=0 dynamic_fraction=0.300000 memdiv=1 

I got a bit confused. I am open to any kind of suggestion. It does not have to be with "sed" command.

p.s: This is my first question here. :)

3 Answers 3

1

with awk

awk '1;/unix/{print "$statistics dscf parallel\n\ $2e-ints_shell_statistics file=DSCF-par-stat\n\ $parallel_parameters\n\ maxtask=4000\n\ maxdisk=0\n\ dynamic_fraction=0.300000\n\ $pardft\n\ memdiv=1"}' file 
Sign up to request clarification or add additional context in comments.

1 Comment

@EdMorton Thought i'd make the most of the last few hours :)
1
sed -i '/unix/ a\ $statistics dscf parallel\ $2e-ints_shell_statistics file=DSCF-par-stat\ $parallel_parameters\ maxtask=4000\ maxdisk=0\ dynamic_fraction=0.300000\ $pardft\ memdiv=1\ ' control 

use simple quote around your sed action and a simple \ at end of line to append

Comments

-1

This might work for you (GNU sed, cat & bash):

cat <<\! | sed -i '/unix/r /dev/stdin' file $statistics dscf parallel $2e-ints_shell_statistics file=DSCF-par-stat $parallel_parameters maxtask=4000 maxdisk=0 dynamic_fraction=0.300000 $pardft memdiv=1 ! 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.