sed already works line by line:
sed -E '/AF|PO/{ ...sed expression to apply when matching... }' server
For example, only print the lines matching that regular expression:
sed -nE '/AF|PO/p' server
The -E flag to sed makes the utility interpret the regular expression as an extended regular expression, and the -n turns off the implicit outputting of every input line.
For doing multiple things to lines matching the expression, enclose these in { ... }. For example, print each matching line twice (and don't print non-matching lines):
sed -nE '/AF|OP/{p;p;}' server
sedwith here-stringsed .... <<<"$i"as well as piping to itecho "$i" | sed ..... – αғsнιη Mar 21 '18 at 16:21sedfor something, you need to figure out whether it's the correct tool for the job.sedis a *stream* editor, that's stream editor. It's not designed for doing what you want. Don't get me wrong; you could wire something up Rube Goldberg style, but don't. Just pick the correct tool for the job. See my answer below. – user1404316 Mar 21 '18 at 16:22