Hi

Perhaps omeone might answer this tricky problem. I can do this other ways, but i really want to understand how to solve it using ed. I have one solution using g/re/s/re//txt/ , but I want to understand how or if i can solve it using the ed (.)a command.

A script i have parse several files and append text after a specific text is matched. If one file do not have this text, i get a no match and the script terminates. How can I avoid this behavior keeping the original coding style for ed and append text. I have tried tried but still cannot get it correct using (.)a. Is it even possible to do it that way using the (.)a command?

Thanks in advance
Thomas


code example that give a "no match". Fairly easy to read and understand

example 1:
-----------
for RFILE in $RLIST; do
ed - RFILE <<- EOF
    H
    /\[matching_text_1\]/a
    This is the appended textline(s) for text1
    .
    /\[matching_text_2\]/a
    This is the appended textline(s) for text2
    .
    w
    q
EOF
done

Another example that solve the above problem. But this example become very easy unreadable if the appended text is long and/or includes linebreaks.

Example 2:
----------
for RFILE in $RLIST; do
ed - $RFILE << EOF
    g/text1/s//text1\\
    appended_text1/g
    g/text2/s//text2\\
    appended_text2/g
    w
EOF
done
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

Reply via email to