| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
Sven,
Here's a way (I think) to include the filter in a shell wrapper (filter.sh file). In this case, I think using a wrapper is better than solely relying upon sed, because it gives you a lot more flexibility to use other tools (tr, grep, awk, ex, etc).
$ cat input.txt
Hello, Dan!!!
------------------------------------
Posted by: Sven Guckes <sven@...>
------------------------------------
$ cat sed.txt
s/Hello/Goodbye/g
$ cat ex.txt
/^Posted by:/-1,//+1d
wq
$ cat filter.sh
#!/bin/bash
TMP_FILE=/tmp/tmpfile-$$
trap "rm -f $TMP_FILE" 0 2 9 15 # No clutter
cat > $TMP_FILE # Filter in
sed -i -f sed.txt $TMP_FILE # Modify content with sed
cat ex.txt | ex -s $TMP_FILE # Modify content with ex
# Modify content with awk, or whatever
cat $TMP_FILE # Filter out
# EOF
$ cat input.txt | filter.sh
Goodbye, Dan!!!
Using a wrapper, and especially using ex, will not be as fast as using pure sed, as you point out. However, in practice the difference is usually not perceptible. I use sed thousands of times most days, and write new sed code just about every day, but almost always within a shell or C wrapper. Of course, I also have an e3-1245 cpu. If it ends up too slow for you, then you might need to do something different.
I rarely use awk. It is surprisingly powerful and clean. However, I just never need awk. I use "sed / tr / grep / cut / paste / etc." for simple operations, shell scripts for wrappers and moderately complex operations, and C for wrappers and greatly complex operations. Nothing wrong with awk. I just don't currently need it.
I hope this helps some. Just opinions based on my experience.
Daniel
[Non-text portions of this message have been removed]